K
kailang.deng
Hello,everybody
I have a program as follows.
class ClassA
{
public:
int buff[1];
virtual void test(void) {cout<<"ClassA::test()"<<endl;}
};
void entry(void)
{
cout<<"Hey,i am here!"<<endl;
}
ClassA Obj1,Obj2,*pObj;
int main()
{
pObj=&Obj2;
//Test group 1
Obj2.test();
pObj->test();
//Obj1.buff[1] covers the pvftable field of Obj2
int vtab=(int)(entry);
Obj1.buff[1]=(int)&vtab;
//Test group 2
Obj2.test();
pObj->test();
return 0;
}
The result is:
ClassA::test()
ClassA::test()
ClassA::test()
Hey,i am here!
Then,it is the point that i am confused.
In my viewpoint,after covering the pvftable field of Obj2,both Obj2
and pObj should invoke the function entry and print "Hey,i am here!".
Then i disassemble the program,it likes as follow
Obj2.test();
00401202 mov ecx,offset Obj2 (0042e168)
00401207 call @ILT+20(ClassA::test) (00401019)
pObj->test();
0040120C mov eax,[pObj (0042e158)]
00401211 mov edx,dword ptr [eax]
:
:
0040121B call dword ptr [edx]
These disassembly codes may have explain the print result.
But can anybody explains the differences between the object and the
pointer points to object?
Thanks a lot!
-Bruce
I have a program as follows.
class ClassA
{
public:
int buff[1];
virtual void test(void) {cout<<"ClassA::test()"<<endl;}
};
void entry(void)
{
cout<<"Hey,i am here!"<<endl;
}
ClassA Obj1,Obj2,*pObj;
int main()
{
pObj=&Obj2;
//Test group 1
Obj2.test();
pObj->test();
//Obj1.buff[1] covers the pvftable field of Obj2
int vtab=(int)(entry);
Obj1.buff[1]=(int)&vtab;
//Test group 2
Obj2.test();
pObj->test();
return 0;
}
The result is:
ClassA::test()
ClassA::test()
ClassA::test()
Hey,i am here!
Then,it is the point that i am confused.
In my viewpoint,after covering the pvftable field of Obj2,both Obj2
and pObj should invoke the function entry and print "Hey,i am here!".
Then i disassemble the program,it likes as follow
Obj2.test();
00401202 mov ecx,offset Obj2 (0042e168)
00401207 call @ILT+20(ClassA::test) (00401019)
pObj->test();
0040120C mov eax,[pObj (0042e158)]
00401211 mov edx,dword ptr [eax]
:
:
0040121B call dword ptr [edx]
These disassembly codes may have explain the print result.
But can anybody explains the differences between the object and the
pointer points to object?
Thanks a lot!
-Bruce