嵌套中的继承 class
Inheritance in nested class
我想要一个 class Type
和三个 class Integer
、Real
和 String
扩展 Type
。是否可以将三个 class 嵌套在 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
作为标识符。
我想要一个 class Type
和三个 class Integer
、Real
和 String
扩展 Type
。是否可以将三个 class 嵌套在 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
作为标识符。