Is there ever any use of the name of the enum? or why is it there?
I looked through the code of the program and the enum name was never used or anything. I don't understand enums completely, so is there something im misinterpreting?
You can distinguish them(FirstEnum::White, SecondEnum::White).
How would you distinguish these?
1 2 3 4 5 6 7 8 9 10 11
enum
{
WHITE,
BLACK,
};
enum
{
WHITE,
BLACK,
};
:)
And downside of enum classes is that... they are more like classes then like enums. You have to call them y EnumName::MemberName, which can get pretty annoying, also - no automatic conversions to int(which you may be used to, and sometimes you may want to use it). But on the other hand, strongly typed enums are what enums really should be.
For the sake of completeness, consider the following scenario.
I'm writing a card game, and I've decided to have these constant integers represent a set of discrete values - in this case, the suit of the cards.
The problem is, that I can pass any integer to the suit_name() function. With an enum, I can guarantee that only a suit enum can be passed, as anything else would be illegal.
even using named enums, like in this case, i dont think it's possible to identify elements with the same name twice (i.e. WHITE or BLACK), even in the case the element is in 2 different enums (conflicting declaration).
i might be wrong though.. it doesnt compile for me anyway