O'Reilly logo

C++ Primer, Fifth Edition by Barbara E. Moo, Josée Lajoie, Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required