我想要一个类 Type
和三个类 Integer
、Real
和 String
扩展类型
。是否可以将这三个类嵌套在 Type
中?这样我就可以编写 Type::Integer int
并获取一个 Type::Integer
类型的对象,该对象继承自 Type
?
class Type {
class Integer : public Type {
};
class Real : public Type {
};
class String : public Type {
};
};
Type::Integer int;
最佳答案
在不考虑设计的合理性的情况下:
class Type {
public:
class Integer;
class Real;
class String;
};
class Type::Integer : public Type{};
class Type::Real : public Type{};
class Type::String : public Type{};
旁注:您不能使用 int
作为标识符。
关于c++ - 嵌套类中的继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28984319/