Encapsulation of Private Enumeration

Earlier, I defined enumerated types that should be private in the class header file.

private: enum foo { a, b, c }; 

However, I do not want details on this being listed. Does an enumeration in an implementation define similarly to the definition of class invariants?

 const int ClassA::bar = 3; enum ClassA::foo { a, b, c }; 

I am wondering if this syntax is correct.

+4
source share
2 answers

C ++ does not have advanced enumeration declarations, so you cannot separate the "type" of an enumeration from the "enum" implementation.

In C ++ 0x, the following is possible:

 // foo.h class foo { enum bar : int; // must specify base type bar x; // can use the type itself, members still inaccessible }; // foo.cpp enum foo::bar : int { baz }; // specify members 
+9
source

No, enum ClassA::foo { a, b, c }; Invalid syntax.

If you want to move the enumeration from the header and into the implementation file (.cpp), just do it. If you want to use an enumeration for the parameter types of class methods, then you cannot move it, so just leave it closed.

+2
source

All Articles