I have to clean a piece of code... it looks something like this:
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 ();
}
The problem comes in the commented line, when commented, fails with the error "cannot instantiate abstract class".
I'll probabily use a reference in the InterfaceA replacing the inheritance... but, Is there any way to do it while maintaining the inheritance?
Aucun commentaire:
Enregistrer un commentaire