lundi 17 février 2020

Multiple inheritance and "this" pointer being cast to common base class

Consider the following code:

class Base {
  //some code
};

class A : public virtual Base{
    //some code
};

class B : public virtual Base{
    //some code
};

class C:  public A, public B {
    //some code
}; 

In other words we have multiple inheritance and all classes inherit from class Base. Now consider that the "this" pointer exists in code in classes A,B,C,Base. I know that in general we cannot assume that the "this" pointer value will be identical in all cases. But what it the "this" pointer is cast to the Base* class inside A,B,C whenever it is used. Is it correct to say that the casted pointer "this" after casting to the common Base* class will contain the same address inside A,B,C? Thanks

Aucun commentaire:

Enregistrer un commentaire