It is automatically converted to the base type derived class method calls the base class

class A
{
    public:
    int a;
    void showthis()
    {
        printf("from A,this:%p\n", this);
    }
};
class B
{
    public:
    int b;
    void infothis()
    {
        printf("from B,this:%p\n", this);
    }
};
class C:public A, public B
{
    public:
    C(){
        printf("from C:this:%p\n", this);    
    }
};

int main()
{
    C c;
    c.showthis();
    c.infothis();
    
    return 0;
}

Compile and run, output:

from C:this:0x7ffff4321a80
from A,this:0x7ffff4321a80
from B,this:0x7ffff4321a84

Type conversion may be accompanied by changes in this address, this base class and derived classes referred to this deviation, transformed into the base class to this pointer.

Guess you like

Origin www.cnblogs.com/xiang-yin/p/12076262.html