I have a problem with multiple inheritance and it would be great if someone could help me out. I am programming a situation which ultimately boils down to something similar to this
class A {
public:
A(){}
virtual ~A() = 0;
virtual void print()=0;
};
A::~A(){}
class B: public virtual A {
public:
B():A(){}
virtual ~B() = 0;
virtual void print() {
cout << "Hello" << endl;
}
};
B::~B(){}
class C: public virtual A {
public:
C():A(){}
virtual ~C() = 0;
virtual void print () {
cout << "Bye" << endl;
}
};
C::~C(){}
class D: public B, public C {
public:
D():B(),C(){}
virtual ~D(){}
virtual void print(){}
};
int main()
{
D d;
A* a = &d;
a->B::print(); //The statement leads to errors
a->C::print(); //The statement leads to errors
}
I need to access the the implementation of the virtual function in class B and class C. Is there a way to do this?
D* a = &d;fixes that.print()from the upper classes and not have a pointer to D which kills the dispatching