Virtual Function and Multilevel Inheritance


Consider these C++ classes
class myClassBase
{
public:
    int baseMember;
    myClassBase() { baseMember = 0; }
    virtual int baseMethod(int x) { return baseMember + x; }
};
class myClassDerived : public myClassBase
{
public:
    int derivedMember;
    myClassDerived() { derivedMember = 0; }
    virtual int derivedMethod(int x) { return derivedMember + x; }
};
class myClassDerived2 : public myClassDerived
{
    int derivedMember2;
    virtual int derivedMethod2(int x) { return derivedMember2 + x; }
};

If we instantiate myClassDerived2 then
Here is the diagram describing the relations:

 

up