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?
A class is a user-defined blueprint or prototype from which objects are created. Basically, a class combines the fields and methods(member function which defines actions) into a single unit. A structure is a collection of variables of different data types under a single unit.
In this article, we will discuss structures, unions, and enumerations and their differences. The structure is a user-defined data type that is available in C++. Structures are used to combine different types of data types, just like an array is used to combine the same type of data types.
An enum just spills its contents into the enclosing scope, and is basically a const static integer. This means that the first element of any default enum is the same using the == operator. Enum classes have their own scope, and don't pollute the namespace that they are in.
Declaring the enum inside the struct is fine and the way you've laid it out is how I did it as well. You won't be able to access the enum Status outside of the Task struct, but for this challenge that's not something to be concerned about. Posting to the forum is only allowed for members with active accounts.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With