While he answers the question, he did not take into account how I always used transfers. Despite the fact that they are simply more or less names for numbers, I always used them to define types that can have only certain values.
If an enumeration is part of a class, this helps consumers clearly identify the enumeration link:
class Apple { enum Variety { Gala, GoldenDelicious, GrannySmith, Fuji } ... };
Then consumers will be able to declare enumeration instances, pass as parameters and define them when referring to one of the types.
unsigned int GetCountOfApples( Apple::Variety appleVariety ); ... fujiCnt = GetCountOfApples( Apple::Fuji );
Sometimes you want to list outside a class or two enumerations in the same class, and you can do something like what Poyo had. However, you cannot refer to the type of enumeration, so just name it.
namespace Color { enum ColorEnum { Blue, Red, Black };
Now using enumeration and values will work as follows:
Color::ColorEnum firstColor = Color::Blue; Color::ColorEnum secondColor = Color::Red; if( firstColor == secondColor ) ....
Now, if they have different enumerations with the same name, they will always match the type. Then you could handle the question that Gambor is asking about.
BananaColorEnum banCol = BananaColor::Yellow; TomatoColorEnum tomCol = TomatoColor::Yellow;
jmc Apr 13 2018-12-12T00: 00Z
source share