64,646
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
/*
问题一:
this指针来自哪里?
在哪将其值设立进的呢?
又是备份于哪个地方的呢?
*/
class AAA
{
public:
void printthis(void)
{
AAA *pThis = this;
/*
mov eax,dword ptr [ebp-8]
mov dword ptr [ebp-14h],eax
ebp是0x0012fe84,减8是0x0012FE7C,内存着"5c ff 12 00"
经过这一步,pThis是0x0012ff5c
*/
cout << "'this' pointer is : " << this << endl;
cout << "'this' pointer is : " << pThis << endl;
}
int m_a1;
int m_a2;
};
int _tmain(int argc, _TCHAR* argv[])
{
AAA a;
a.m_a1 = 1;
/*
mov dword ptr [ebp-0Ch],1
ebp是0x12ff68,减c是0x0012FF5C,就是this了
*/
a.m_a2 = 2;
/*
mov dword ptr [ebp-8],2
*/
a.printthis();
/*
lea ecx,[ebp-0Ch]
call 0041120D
ebp是0x12ff68,减c是0x0012FF5C,就是this了
透过对象a调用printthis函数,会先传进一个this指针.
*/
return 0;
}
using namespace std;
class T
{
public:
T()
{
cout << (int *)this << endl;
};
int i;
char c;
};
int main()
{
T t;
cout << (int *)(&t) << endl;
return 0;
}