Thursday, October 22, 2009

C++ - Referring to an enum inside a type

When you refer to an enum inside a type, you do not have to specify the name of the enum. See the code snippets below.

Say you have a class like what is given below.

class MyClass {
enum MyEnum { a };
};


Incorrect use of a value of type MyEnum



int i = MyClass::MyEnum::a;


Correct use of a value of type MyEnum



int j = MyClass::a;

No comments: