草庐IT

c++ - 在 C++ 中,是否可以将一个类声明为从另一个类继承?

我知道我能做到:classFoo;但我可以将一个类声明为从另一个类继承吗,例如:classBar{};classFoo:publicBar;一个示例用例是协变引用返回类型。//somewhere.hclassRA{}classRB:publicRA{}...然后在另一个不包含某处的标题中。h//other.hclassRA;classA{public:virtualRA*Foo();//thisonlyneedstheforwarddeceleration}classRB:publicRA;//invalidbut...classB{public:virtualRB*Foo();//}