Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the allowed types for an enum (class)?

Tags:

c++

c++11

c++14

When declaring an enum (class) I can specify the underlying type that the enum will use, e.g.

enum class MyEnum : baseType { FIRST, SECOND };

What can baseType be? The usual choice would be uint32_t or something similar but could it also be float? Or even my own class?

like image 736
user2746401 Avatar asked Feb 10 '23 02:02

user2746401


1 Answers

N4140 [dcl.enum]/2: [...] The type-specifier-seq of an enum-base shall name an integral type; any cv-qualification is ignored. [...]

So baseType can be any integral type, i.e. bool, char, char16_t, char32_t, wchar_t and the signed and unsigned integer types.

like image 95
TartanLlama Avatar answered Feb 11 '23 14:02

TartanLlama