There is no βbetterβ solution, because, of course, this is a very subjective term.
Given that you mention constants that are used somewhere else, we can say that they must be declared either in protected (if they should be used exclusively by derived classes), or, most likely, in the public section of the class.
Constants that do not have an integer type must be defined as members of the static const (but you need to follow the order of static initialization if there are other static objects that relate to these constants).
Constants of integer type can be declared as static const int or as enumerations, as you already mentioned. The distinguishing factor here is whether two or more constants can be logically grouped together.
For example, this is probably a good idea:
class MyClass { public: enum { Color_Red, Color_Green, Color_Blue, }; };
So far this is not the case:
class MyClass { public: enum { Color_Red, Vehicle_Car, }; };
Jon
source share