There are couple of questions regarding this.But I am still not clear about this. Consider this multiple inheritance.
class Base1
{
public:
Base1();
virtual ~Base1();
virtual void speakClearly();
virtual Base1 *clone() const;
protected:
float data_Base1;
};
class Base2
{
public:
Base2();
virtual ~Base2();
virtual void mumble();
virtual Base2 *clone() const;
protected:
float data_Base2;
};
class Derived : public Base1, public Base2
{
public:
Derived();
virtual ~Derived();
virtual Derived *clone() const;
protected:
float data_Derived;
};
and consider these two statements
Base1 *pbase1 = new Derived;
Base2 *pbase2 = new Derived;
The book inside the C++ Object model states that in one of the optimization.
The vtable of pbase1 subobject and Derived share the same vtable. Exact phrase in the book
"Base 1 being leftmost, it already points to the beginning of the Derived class object "
How does this happen? I understand this will change if I change the order of inheritance as
class Derived : public Base2, public Base1
But I dont understand how this is done by the compiler. Can anybody explain how pbase1 and derived share the same v_table?