I am trying to figure out an interesting problem of multiple inheritance.
Grandparents are an interface class with several methods:
class A { public: virtual int foo() = 0; virtual int bar() = 0; };
Then there are abstract classes that partially complete this interface.
class B : public A { public: int foo() { return 0;} }; class C : public A { public: int bar() { return 1;} };
The class that I want to use inheritance from both parents, and indicates which method should come from where using directives:
class D : public B, public C { public: using B::foo; using C::bar; };
When I try to create an instance of D, I get errors for trying to create an abstract class.
int main() { D d; //<-- Error cannot instantiate abstract class. int test = d.foo(); int test2 = d.bar(); return 0; }
Can someone help me understand the problem and how best to use partial implementations?
c ++ inheritance multiple-inheritance diamond-problem
Michael
source share