Reputation: 48958
Looking at the enum
documentation, there was one thing that I noticed:
enum-key - one of
enum
,enum class
(since C++11), orenum struct
(since C++11)
enum
and enum class
, sure, but what is a enum struct
?
The docs seem to say that enum class
and enum struct
are exactly the same:
[...] scoped enumeration (declared with the enum-key
enum class
orenum struct
)
enum struct
|class
name{ enumerator = constexpr , enumerator = constexpr , ... }
- [...]
Are they really exactly the same? Or are there any differences that I missed? What is the point (if they are the same) to have 2 different syntax for the same thing?
Upvotes: 51
Views: 28627
Reputation: 238351
enum class
, sure, but what is aenum struct
?
Same as enum class
.
Are they really exactly the same?
Yes. The documentation is correct.
Or are there any differences that I missed?
No. There are no differences.
What is the point (if they are the same) to have 2 different syntax for the same thing?
I haven't found any written rationalization for the decision. There isn't any in the standard nor the proposal. One might guess that it is some sort of counterpart to class
vs struct
class-keys. This is an opposite decision than was made when template<class T>
syntax was specified, where struct
is not allowed.
Upvotes: 29
Reputation: 32576
enum class
and enum struct
are the same (emphasis mine).
7.2 Enumeration declarations
...
2 .... The enum-keysenum class
andenum struct
are semantically equivalent; an enumeration type declared with one of these is a scoped enumeration, and its enumerators are scoped enumerators.
Upvotes: 54