例如:
struct C1
{
public:
virtual void D1() = 0;
};
class C2
{
public:
virtual void D2() = 0;
};
class C : public C1, public C2
{
public:
virtual void D1()
{
C* p = this;
C1* q = this;
C2* r = this;
}
virtual void D2()
{
C* p = this;
C1* q = this;
C2* r = this;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
C c;
c.D1();
c.D2();
return 0;
}
this指针会在转换时调整
D1中this: 0x0035f7fc p: 0x0035f7fc q: 0x0035f7fc r: 0x0035f800
D2中this: 0x0035f800 p: 0x0035f7fc q: 0x0035f7fc r: 0x0035f800
近期评论