- #1
yungman
- 5,755
- 293
I don't understand this header file in the book. In line 4, it declares static int objectCount;
I tried to put static int objectCount = 0; it won't compile, I tried putting in the next line objectCount = 0; it doesn't work. I tried putting in line 6, it doesn't work.
Being declare in private, obviously Tree:bjectCount = 0 in main() won't work.
Then the book put that in line 11 OUTSIDE the Class definition, it works.
I don't understand any of this, can anyone explain to me. What is the statement in line 11 called?
Thanks
I tried to put static int objectCount = 0; it won't compile, I tried putting in the next line objectCount = 0; it doesn't work. I tried putting in line 6, it doesn't work.
Being declare in private, obviously Tree:bjectCount = 0 in main() won't work.
Then the book put that in line 11 OUTSIDE the Class definition, it works.
I don't understand any of this, can anyone explain to me. What is the statement in line 11 called?
C++:
class Tree
{
private:
static int objectCount;//Static member variable
public:
//objectCount = 0;
Tree() { objectCount++; }// Constructor
int getobjectCount() const { return objectCount; }
};
#endif
int Tree::objectCount = 0;
Thanks