Consider following simple example:
#include <iostream>
using namespace std;
class A {
public:
virtual void foo() {
cout<<"A"<<endl;
}
};
class B: public virtual A {
public:
virtual void foo(){
cout<<"B"<<endl;
}
};
class C : public virtual A {
public:
virtual void foo(){
cout<<"C"<<endl;
}
};
class D : public B, public C {
public:
void print(){
foo();
}
};
int main () {
D d;
d.print();
return 0;
}
This code will not work, because call to foo is ambigous. But question is:
How can I define which methods from which classes should be inherited? And if I have the such opportunity?