Enumerators
The names of the enumerators in a scoped enumeration follow normal scoping rules and are inaccessible outside the scope of the enumeration. The enumerator names in an unscoped enumeration are placed into the same scope as the enumeration itself:
enum color {red, yellow, green}; // unscoped enumerationenum stoplight {red, yellow, green}; // error: redefines enumeratorsenum class peppers {red, yellow, green}; // ok: enumerators are hiddencolor eyes = green; // ok: enumerators are in scope for an unscoped enumerationpeppers p = green; // error: enumerators from peppers are not in scope // color::green is in scope but has the wrong typecolor hair = color::red; // ok: we can explicitly access the enumerators ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access