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行,没有列表项,要枚举干嘛?

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
  • 2021-12-22
  • 2022-03-06
  • 2021-07-19
  • 2022-02-28
  • 2021-09-10
猜你喜欢
  • 2021-08-19
  • 2021-12-13
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-26
相关资源
相似解决方案