I think this is more a stylistic question, but I have a class with an enum for statistic distribution type (that is only used in this class):
Entity {
public:
enum DistributionType {NORM, UNIFORM_INT, UNIFORM_SPECIFIED, BINOMIAL };
distributionType ds;
...
}
I want to make a DistributionType value as a parameter for my constructor:
Entity salesVolume = new Entity(Entity::DistributionType.NORM);
but this doesn’t work (I guess it expects DistributionType when it’s being passed an int value?)
What is the right way to call a constructor with an enum value that is part of that same class? I could do it by typecasting to int, but this doesn’t seem very tight. I could also exclude the enum from the class and define it separately (which I’ve seen) – is that a more common way to do it?
Thanks guys
With enums, there is no “namespace”, so you need this:
C++11 provides “enum classes” or “strongly typed enums” to solve this weirdness. It also allows you to use the enum name as a “scope” for traditional enums, so you could do this too: