1 #include <iostream> 2 3 int main() 4 { 5 enum class Color : unsigned char { Red, Green }; 6 enum class Alert : bool { Red, Green }; 7 8 //Color c; 未初始化 9 //Color c{65}; //明显的枚举范围外,但是在unsigned char范围内 10 //Color c{ Alter::Red} ; 类型不匹配 11 12 using color_rep_type = std::underlying_type<Color>::type; 13 std::cout << "c=" << static_cast<color_rep_type>(c) << std::endl; 14 15 enum class Test: int { }; //没有枚举列表的枚举类 16 17 }
第9行,虽然不合逻辑,但是也能编译通过。
第15行,没有列表项,要枚举干嘛?
原文链接: https://www.cnblogs.com/thomas76/p/8722156.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;
也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/397504
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!