ok...this is a pretty lame question:
I was reading Scott Meyer's "Effective C++", and on item E1, he writes this:
I doubt when he calls the "definition part" as "mandatory", because it should run fine without this explicit definition. (further...he is "defining" a private const member...is this allowed ??)To limit the scope of a constant to a class, you must make it a member, and to ensure there's at most one copy of the constant, you must make it a static member:
There's a minor wrinkle, however, which is that what you see above is a declaration for NUM_TURNS, not a definition. You must still define static class members in an implementation file:Code:class GamePlayer { private: static const int NUM_TURNS = 5; // constant declaration int scores[NUM_TURNS]; // use of constant ... };
Code:const int GamePlayer::NUM_TURNS; // mandatory definition; // goes in class impl. file