c++ – Enum: type {}; What is the default type?

Question:

In C ++ 11, there was such a possibility as:

enum AnyEnum : int8_t {
    a = -1,
    b = 0,
    c = 1,
};

What type is set by default, ignoring the various optimizers? Earlier, if I am not mistaken, int; set int;

Those. what will be delivered at compile time if the type is not specified?

Answer:

The documentation for std::underlying_type states that:

The underlying type of an enum declared with enum class is int unless a different type is specified on declaration.

In translation:

The base type of an enumeration declared as an enum class is int unless a different type is specified in the declaration.

Scroll to Top