class A {
public: enum class { HELLO, WORLD };
};
Having known that, inside a class
, declaring a simple enum
(rather than enum class
) is a better idea, because it's already typed with the class
identification. But still above statement is a valid C++0x
signature. Now how to access an unnamed enum class
outside ?
int i = A::HELLO; // error: ‘HELLO’ is not a member of ‘A’
Actually, that is not valid. The C++0x FDIS says (9.2p1)
Except when used to declare friends (11.3) or to introduce the name of a member of a base class into a derived class (7.3.3), member-declarations declare members of the class, and each such member-declaration shall declare at least one member name of the class.
In your case, no enumerator name is introduced into the class' scope and no enumeration name is introduced either. So, no member name at all is introduced by that member-declaration.
EDIT: And actually, there's a more direct prohibition of the enumeration declaration. 7.2p2:
The optional identifier shall not be omitted in the declaration of a scoped enumeration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With