enum classColor { red, green = 20, blue }; Color r = Color::blue; switch(r) { case Color::red : std::cout << "红\n"; break; case Color::green: std::cout << "绿\n"; break; case Color::blue : std::cout << "蓝\n"; break; } // int n = r; // 错误:不存在从有作用域枚举到 int 的隐式转换 int n = static_cast<int>(r); // OK, n = 21
enum classType { General, Light, Medium, Heavy };
enum classTypeC :char { General, Light, Medium, Heavy }; enum classTypeUI :unsignedint { General, Light, Medium, Heavy };