[Solved] Referring to c++ enums [closed]


In all versions of C++, the second version (Foo::States::BAR) using scope syntax is the more conventional and will be less surprising for future maintainers of your code. Since the value is a constant, there is no need for an instance of the class, so this is similar to how static methods are most often called with scope syntax rather than instance syntax.

The one motivation for calling static methods on an instance might be to make it more similar (compatible) with a non-static method call, but that motivation is largely irrelevant for your enum example, not least of all because a possible future change to make your enum into a variable would make it look “wrong,” i.e. BAR in all caps is understood by most programmers to be a constant value, not a variable, and it has been this way since perhaps the 1970’s.

solved Referring to c++ enums [closed]