When does C++ define the underlying types of enumerations
This article is mainly about "when does C++ define the underlying types of enumerations", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn when C++ defines the underlying types of enumerations.
Enum.7: define the underlying types of enumerations only when necessary
Reason (reason)
The default type is easier to read and write. Int is the default integer type. Int and C language enumerated types are compatible.
Example (sample)
Enum class Direction: char {n, s, e, w
Ne, nw, se, sw}; / / underlying type saves space
Enum class Web_color: int32_t {red = 0xFF0000
Green = 0x00FF00
Blue = 0x0000FF}; / / underlying type is redundant
Note (Note)
The underlying type of the enumeration needs to be defined when the enumeration is declared before.
Enum Flags: char
Void f (Flags)
/ /....
Enum flags: char {/ *... * /}
At this point, I believe you have a better understanding of "when C++ defines the underlying types of enumerations". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!