nT in here

nT in here
Last edited on
That's because you're ignoring the context.
A‘‘plainenum’’ isroughly what C++ offered before the enum classes were introduced, so you’ll
find them in lots of C and C++98-style code.
He's explaining what happened in C++98.

Once a symbols is defined in an enum, it cannot be reused in a different enum because the value is still visible. So you get an error when there's an attempt to redine an existing symbol.

This has changed with the introduction of enum classes in C++11.
Last edited on
@Starhowl

Pleas don't delete your question after it's been answered. It ruins the value of forum threads as an archive of help for people who search for answers here.
I will repost OP here:

Starhowl wrote:
[The C++ Programming Language (4th Edition)] enums

On p. 222 in 8.4.2 there are the following 2 comment lines:

1
2
3
4
5
enum Traffic_light {red, yellow, green};
enum Warning {green, yellow, orange, red}; // fire alert levels

// error: two definitions of yellow (to the same value)
// error: two definitions of red (to different values)  


,

but I fail to understand why - once - they are of same value and - second - of different value (aside from green being left out in the example)?
Last edited on
Topic archived. No new replies allowed.