我必须清除一段代码...看起来像这样:
struct InterfaceA { virtual void foo () = 0; };
struct InterfaceB : public InterfaceA { virtual void var () = 0; };
struct ImplA : public InterfaceA
{
void foo () { std::cout << "foo" << std::endl; }
};
struct ComplexImpl : public InterfaceB, public ImplA
{
void var () { std::cout << "var" << std::endl; }
//void foo () { ImplA::foo (); } // <<=== I want to erase this
};
void herenciaCompleja ()
{
ImplA x;
x.foo ();
ComplexImpl y;
y.foo ();
}
问题出现在注释行中,注释时失败,并显示错误“无法实例化抽象类”。
我将很可能在InterfaceA中使用一个引用来代替继承...但是,在保持继承的同时有什么方法可以做到这一点?