this指针的值
this指针指向的是对象的地址,与对象第一个成员变量的关系是怎样的呢?看下面这个例子:
struct CPlex{
CPlex* pNext;
void* data() { return this+1; }
};
int main(int argc, char* argv[])
{
CPlex p;
void* add1 = (void*)&p;
void* add2 = (void*)&(p.pNext);
void* add3 = (void*)p.data();
return 0;
}
在调试器中看到各个变量的值:
add1= 0x0012ff44
add2 =0x0012ff44
add3 =0x0012ff48
其实this指针的值与对象第一个成员变量一样。

浙公网安备 33010602011771号