What is the difference between enum struct and enum class?

Looking at the enum documentation , I noticed one thing:

enum-key - one of enum , enum class (since C ++ 11) or enum struct (since C ++ 11)

enum and enum class , of course, but what is enum struct ?

The docs seem to say that the enum class and enum struct are exactly the same:

[...] scope enumeration (declared using enum class or enum struct enumeration)


  • enum struct | class name { enumerator = constexpr , enumerator = constexpr , ... }
  • [...]
Are they really the same? Or are there any differences that I missed? What is the point (if they are the same) of having 2 different syntaxes for the same?
+5
source share
2 answers

enum class and enum struct are the same (focus).

7.2 Listing declarations


2 .... enum class and enum struct enumeration variables are semantically equivalent ; the type of enumeration declared by one of them is a copied enumeration, and its counters are taxed with counters.

+7
source

enum class , of course, but what is an enum struct ?

Same as enum class .

Are they 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) of having 2 different syntaxes for the same thing?

I did not find any written rationalization for the solution. In the standard and the proposal there is not one. You can guess that this is a kind of analogue of class vs struct class-keys. This is the opposite solution than what was indicated when the syntax template<class T> was specified, where struct not allowed.

+3
source

All Articles