c**z 发帖数: 669 | 1 complier能过,但是run不过,请指教
class book
{
public:
book(long id1,string detail1 )
{ id=id1; detail=detail1;
}
book()
{
}
void addbook(long id2, string detail2)
{ book b(id2,detail2);
books.push_back(b);
}
private:
long id;
string detail;
static vector books;
};
void main()
{
book b1;
b1.addbook(1,"a");
b1.addbook(2,"b");
} | q****x 发帖数: 7404 | 2 add this line after the class definition:
vector book::books;
the line of static ... in your code is a declaration, not definition. the
variable must be defined before used.
【在 c**z 的大作中提到】 : complier能过,但是run不过,请指教 : class book : { : public: : book(long id1,string detail1 ) : { id=id1; detail=detail1; : } : book() : { : }
| l***i 发帖数: 1309 | 3 In addition, don't you need to declare the function with static? | a********m 发帖数: 15480 | | f*******t 发帖数: 7549 | |
|