user2746401
user2746401

Reputation: 3436

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, 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?

Upvotes: 4

Views: 192

Answers (1)

TartanLlama
TartanLlama

Reputation: 65770

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.

Upvotes: 8

Related Questions