In C++, a member marked static
is shared by all instances of a given class. Whether it's private or not doesn't affect the fact that one variable is shared by multiple instances. Having const on there will warn you if any code would try to modify that.
If it was strictly private
, then each instance of the class would get its own version (optimizer notwithstanding).
^This is what i read here. My question is, why is it better to have static const int
instead of putting the desired variable in private
? I know each object would get its own, but why is it bad?