I cannot figure out what would happen in the following scenario:
class MBase {
public:
MBase(int) {}
virtual char* vf() const = 0;
virtual ~MBase() {}
};
class D1 : public MBase { //NOT VIRTUAL!!!
public:
D1() : MBase(1) {}
char* vf() const { return "D1"; }
};
class D2 : virtual public MBase {
public:
D2() : MBase(2) {}
char* vf() const { return "D2"; }
};
class Bottom : public D1, public D2 {
public:
char* vf() const { return "Bottom"; }
}
Base* b = new Bottom();
In the original definition of the diamond both D1 and D2 were inheriting virtually from MBase, but here only one is. Would we still have two separate subobjects in Bottom object and therefore, the last line will not compile as compiler won’t know which subobject to use?
This is specified in section 10.1.4 of the C++03 standard. Virtual and non-virtual bases are independent, so there will be one of each.
It is easy to see this by expanding your example:
Outputs: