For a class that has some enumeration that defines the type of class, as in the following example:
class Fruit {
public:
enum class FruitType {
AppleType = 0,
OrangeType = 1,
BananaType = 2,
};
Fruit(FruitType type) : type_(type) {}
FruitType fruit_type() const { return type_; }
private:
FruitType type_;
};
and a class derived from it that has the same enumeration:
class DriedFruit : public Fruit {
public:
};
Is there any way to define different types for Fruit and DriedFruit with each of the specific enumeration values:
class Apple // Fruit with FruitType = AppleType
class Orange // Fruit with FruitType = OrangeType
class Banana // Fruit with FruitType = BananaType
class DriedApple // DriedFruit with FruitType = AppleType
class DriedOrange // DriedFruit with FruitType = OrangeType
class DriedBanana // DriedFruit with FruitType = BananaType
so 3 classes Apple, Orange and Banana are different types, and 3 classes DriedApple, DriedOrange, DriedBanana are different types.
My question is somewhat similar to How to define different types for the same class in C ++ , except that I want to explicitly store class type information as an enum member variable in the class and have a common base class for all different types.
?
EDIT:
: , Apple , , , , , .
, / Fruit , Apple, , , , 3 .
:
,
, -
Apple, Fruit Apple, , Apple .