






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







7/13/2015 | Page Division
7/13/2015 | Page Division
enum name { enumerator = constexpr , enumerator = constexpr , ... }
enum name : type { enumerator = constexpr , enumerator = constexpr , ... }
7/13/2015 | Page Division EXAMPLE TRADITIONAL ENUMS enum Color { red, yellow, green= 20 , blue }; Color col = red; int n = blue; // n == 21 struct Foo { enum Direction { left='l', right='r' }; }; Foo x; int a = Foo::left; int b = x.left; int c = Foo::Direction::left; // allowed only in C++11 and later
7/13/2015 | Page Division EXAMPLE IMPLICIT CONVERSION enum class Color { RED, GREEN= 20 , BLUE }; Color r = Color::BLUE; switch(r) { case Color::RED : std::cout << "red" "\n"; break; case Color::GREEN : std::cout << "green" "\n"; break; case Color::BLUE : std::cout << "blue" "\n"; break; } int n = r; // error: no scoped enum to int conversion int n = static_cast
7/13/2015 | Page Division EXAMPLE ENUM FORWARD DECLARATION
7/13/2015 | Page Division