I would like the static member variable to keep track of the number of objects that were made. For example:
class test{ static int count = 0; public: test(){ count++; } }
This does not work because, according to VC ++, a member with an in-class initializer must be constant . Therefore, I looked around and, apparently, you should have done:
test::count = 0;
Which would be great, but I want count to be private.
change Oh boy I just realized what I need to do:
int test::count = 0;
I saw something just test::count = 0 , so I assumed that you would not have to declare the type again.
I would like to know if there is a way to do this inside the class.
edit2:
What I use:
class test{ private: static int count; public: int getCount(){ return count; } test(){ count++; } } int test::count=0;
Now he says: 'test' followed by 'int' is illegal (did you forget a ';'?)
Edit3:
Yup, forgot the semicolon after class definition. I'm not used to doing this.
mowwwalker
source share