[英]What are the allowed types for an enum (class)?
When declaring an enum (class) I can specify the underlying type that the enum will use, eg 在声明枚举(类)时,我可以指定枚举将使用的基础类型,例如
enum class MyEnum : baseType { FIRST, SECOND };
What can baseType
be? baseType
可以是什么? The usual choice would be uint32_t
or something similar but could it also be float
? 通常的选择是
uint32_t
或类似的东西,但它也可以float
? Or even my own class? 甚至是我自己的班级?
N4140 [dcl.enum]/2:
[...] The type-specifier-seq of an enum-base shall name an integral type;N4140 [dcl.enum]/2:
[...] enum-base的type-specifier-seq应命名为整数类型; any cv-qualification is ignored.任何cv资格都被忽略了。 [...]
[...]
So baseType
can be any integral type, ie bool
, char
, char16_t
, char32_t
, wchar_t
and the signed and unsigned integer types. 因此
baseType
可以是任何整数类型,即bool
, char
, char16_t
, char32_t
, wchar_t
以及有符号和无符号整数类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.