You are confusing an enum
with an enum class
. Suppose your code was this:
enum Day {sunday, monday, thuesday, wednesday, thursday, friday, saturday};
Day unusedDay, today = sunday;
Then the above code would compile, since normal enum
's have values that are visible globally, so you can access them like Day unusedDay, today = sunday;
. As for enum class
es, the rules differ a little. For your example to work, you would to write the code like this:
enum Day {sunday, monday, thuesday, wednesday, thursday, friday, saturday};
Day unusedDay, today = Day::sunday;
If you look at the documentation for enum
's vs enum class
es, you see this:
Enum
Declares an unscoped enumeration type whose underlying type is not fixed -
Note the use of the word unscoped here meaning the variable is available just with it's name.
Enum Class
declares a scoped enumeration type whose underlying type is int (the keywords class and struct are exactly equivalent)
As seen here, an enum class
is scoped, and accessibly only as enumname::value
;
(Source)