As mentioned in this question's title, is there a syntax to do this?
class Food : public Edible {
public:
class Fruit : public FruitBase { //note: Fruit must be a class and a subclass of Food.
public:
enum Type { //note: Type must be inside Fruit and must be a plain enum.(not enum class)
APPLE,
GRAPES,
ORANGE,
};
//...
};
enum { CAKE, CHOCOLATE };
//...
};
void func(){
Food snack;
//...
auto typeA = snack.Fruit::APPLE; //<---this is syntax error.
auto typeG = snack.GRAPES; //<---also syntax error.
auto typeO = Food::Fruit::ORANGE; //<---this is OK, but not my target.
auto typeC = snack.CAKE; //<---this is OK.
//...
}
I prefer the syntax of typeG
. My 2nd preference is typeA
. I'm currently using typeO
in my code but I need to access those enum constants from object snack
instead of class Food
. Since typeC
is possible, I hope there's also a way to do this on enums inside a subclass.