Virtual Function and Multiple Base Classes


Let's take this example
class myClassBase
{
public:
    int baseMember;
    myClassBase() { baseMember = 0; }
    virtual int baseMethod(int x) { return baseMember + x; }
};
class myClassBase2
{
public:
    int baseMember2;
    myClassBase2() { baseMember2 = 0; }
    virtual int baseMethod2(int x) { return baseMember2 + x; }
};
class myClassDerived : public myClassBase, public myClassBase2
{
public:
    int derivedMember;
    myClassDerived() { derivedMember = 0; }
    virtual int derivedMethod(int x) { return derivedMember + x; }
};

To understand this, let's us first think that the myClassDerived inherits only from myClassBase, then its equivalent C structure will be
struct myClassDerived
{
    struct myClassBase base;
    int derivedMember;
};

Now if the myClassDerived inherits from both base classes then equivalent C structure will become
struct myClassDerived
{
    struct myClassBase base;
    struct myClassBase2 base2;
    int derivedMember;
};

Here is a diagram describing the relations:


Question: How many vtable pointers will be there with the object of myClassDerived if the myClassBase2 derives from two different classes?
 

up