嵌套类中的继承
Inheritance in nested class
我想有一个类Type
,以及三个类Integer
、Real
和扩展Type
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++从外部类继承的嵌套类;不允许使用不完整的类型
- 嵌套类、继承和C++中的共享指针
- 如何重写继承的嵌套类中存在的虚拟方法
- 返回自身内部的双重嵌套类的成员函数,该类继承自从自身继承的类
- 嵌套结构属性继承
- C++嵌套类从嵌套类继承,请键入 issue
- 如何解释嵌套继承类结构?
- 继承和嵌套名称的陷阱
- 嵌套类继承的错误
- 嵌套类和继承
- 为什么 Visual C++无法编译从私有嵌套类继承的友元模板
- 继承类中嵌套类的可见性
- 为什么 GCC 允许从私有嵌套类继承
- 为什么 GCC 不允许在你是朋友时从私有嵌套类继承
- 在 C++11 中,从私有嵌套类型继承是否合法?
- C++ 嵌套前向声明继承
- 不直观的嵌套类继承
- 我应该在 c++ 中的派生类中继承嵌套类吗?
- 继承嵌套模板类的实现
- 继承嵌套类时出现C4091错误