In C++, enum introduces an
unscoped enumeration,
and enum class or enum struct introduce a
scoped enumeration.
enum class Fruit : char {
NONE, // enumerator-list, NONE = 0
APPLE = 'a',
BANANA = 'b'
};
Fruit apple = Fruit::APPLE;?inline
- underlying type is
int - requires enum-name:: to access
- only
=,==and!=defined (operator overloading possible)
?inline
- underlying type is impl.-defined
- access without enum-name
- behaves like list of constants in surrounding scope
- inherits ops. from underlying type
<:cppreference:875716540929015908>
Enumeration Declaration
<:cppreference:875716540929015908>
Using-enum-declaration (since C++20)
<:cppreference:875716540929015908>
std::underlying_type (since C++11)
<:cppreference:875716540929015908>
std::to_underlying (since C++23)
• learncpp.com: Enumerated Types
?creditFooter 164892896514801664