I want to understand "this" pointer. I thought that "this" pointer refers to the value of the class object. However, in the below code, I could see different values of "this" pointer:
#include <stdio.h>
class InterfaceA{
public:
virtual void funa() = 0;
};
class InterfaceB{
public:
virtual void funb() = 0;
};
void globala(InterfaceA* obj){
printf("globalA: pointer: %p\n\r",obj);
}
void globalb(InterfaceB* obj){
printf("globalB: pointer: %p\n\r",obj);
}
class concrete : public InterfaceA, public InterfaceB{
public:
void funa(){
printf("funa: pointer: %p\n\r",this);
globala(this);
globalb(this);
}
void funb(){
printf("funb: pointer: %p\n\r",this);
globala(this);
globalb(this);
}
};
int main(int argc, char *argv[])
{
concrete ac;
ac.funa();
ac.funb();
return 0;
}
Output of this program gives:
funa: pointer: 0x7ffff67261a0
globalA: pointer: 0x7ffff67261a0
globalB: pointer: 0x7ffff67261a8
funb: pointer: 0x7ffff67261a0
globalA: pointer: 0x7ffff67261a0
globalB: pointer: 0x7ffff67261a8
Any help to understand this.
Thanks.