Is this enumeration valid, and if so, why?

c++

Solution

It's valid in that it's allowed. Probably not a good design though.

As far as why, I'm not sure what answer you are looking for there. If it was not allowed, then it would prevent cases where it made sense to have two enums refer to the same value. (I'm sure I could easily come up with examples where this made sense.)

So if it's a choice between restricting what I can do, or being limited because I'll usually won't want duplicates, then I would have voted for that way it is.

Problem

``` enum color = {blue, black=3, yellow=3}; ``` 2 colors have the value 3, is it valid? I thought an enumeration has to have different values.

Original source