enum主要分为非限定作用域(不带class)和限定作用域这两种。
-
enum xxx {…} // 非限定作用域,枚举中每个成员的作用域和枚举对象相同。
-
enum class xxx {…} // 限定作用域,枚举中每个成员的作用域在作用域中,枚举类型作用域外不可访问。
-
不限定作用域的枚举类型的枚举成员可以自动转换成int,限定作用域不会。
int如何转换成枚举? / 枚举如何转成int?
- https://stackoverflow.com/questions/11452920/how-to-cast-int-to-enum-in-c
- https://stackoverflow.com/questions/53148463/conversion-from-int-to-enum-class-type-possible