Go to main content
Oracle® Developer Studio 12.6: C++ User's Guide

Exit Print View

Updated: July 2017
 
 

4.6 Using an enum Name as a Scope Qualifier

Because an enum declaration does not introduce a scope, an enum name cannot be used as a scope qualifier. For example, the following code is invalid.

enum E {e1, e2, e3};
int i = E::e1; // invalid: E is not a scope name

To compile this invalid code, use the -features=extensions option. The -features=extensions option instructs the compiler to ignore a scope qualifier if it is the name of an enum type.

To make the code valid, remove the invalid qualifier E::.


Note -  Use of this option increases the possibility of typographical errors yielding incorrect programs that compile without error messages.

Note -  C++11 allows declaration of "class enum", creating an enum type with its own scope.