首页 > 编程语言 > 详细

看不懂的C++: enum class

时间:2018-04-05 14:05:09      阅读:226      评论:0      收藏:0      [点我收藏+]
 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行,虽然不和逻辑,但是也能编译通过

看不懂的C++: enum class

原文:https://www.cnblogs.com/thomas76/p/8722156.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!