64,651
社区成员
发帖
与我相关
我的任务
分享
class A
{
private:
int i;
public:
virtual void fun(int a)
{
i = a;
cout<< i <<endl;
}
}
class B : public A
{
private:
int b;
public:
virtual void fun(int a)
{
b = a;
cout<< b <<endl;
}
}
void fun_test(B* const pThis, int a)
{
pThis->b = a;
cout<<pThis->b <<endl;
}
调用:
B b;
A* p = &b;
p->fun(2);
A a = (A)b;
a.fun(1);
fun_test(p, 1);//error
fun_test(&b, 2);//OK
B b;
0127149E lea ecx,[b]
012714A1 call B::B (12710FFh)
A* p = &b;
012714A6 lea eax,[b]
012714A9 mov dword ptr [p],eax
p->fun(2);
012714AC mov esi,esp
012714AE push 2
012714B0 mov eax,dword ptr [p]
012714B3 mov edx,dword ptr [eax]
012714B5 mov ecx,dword ptr [p]
012714B8 mov eax,dword ptr [edx]
012714BA call eax
012714BC cmp esi,esp
012714BE call @ILT+360(__RTC_CheckEsp) (127116Dh)
A a = (A)b;
012714C3 lea eax,[b]
012714C6 push eax
012714C7 lea ecx,[a]
012714CA call A::A (127119Ah)
a.fun(1);
012714CF push 1
012714D1 lea ecx,[a]
012714D4 call A::fun (12711CCh)
//fun_test(p, 1);//error
fun_test(&b, 2);//OK
012714D9 push 2
012714DB lea eax,[b]
012714DE push eax
012714DF call fun_test (1271195h)
012714E4 add esp,8
return 0;
汇编没学好,看不太明白。。。。