There's something about static members I don't understand. Why can static members like int or double only be declared outside the class, not inside the class. It is legal to define a static function inside the class, why not the primitive?
Actually, it's usually inadvisable to define anything inside the class. There's always (well, often) the possibility that the class is declared in more than one file. If that's the case and the class declaration also contains definitions, the linker will throw an error.
will work inside the class declaration and is perfectly fine since the "static" keyword guarantees there is only one copy, regardless of how many times the header gets included.
I've seen several posts (and have made the same mistake myself) where someone declares a static inside a class and then wonders why they get a link error. They (and I) forget that it's just a declaration, NOT a definition. Helios, you are saying (I think) if "static int myInt;" is defined inside the class, rather than just declared, and if another file uses that class, it would be a redefinition (even though identical) of that static in the global space. That makes sense, except then I don't see how the static function can be defined inside a class, since wouldn't that lead to the same redefinition problem?
CoDeReBel and jsmith thanks and I will try some test programs with static const... and the "enum" which I've never seen before. If I understand "const" it can only work as a read only variable but does not allow changing its value.