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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.