锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
TO:鐢║E淇敼Windows 2000 Professional.vmx鏂囦歡,澧炲姞
vmmouse.present = FALSE
svga.maxFullscreenRefreshTick = 5
#include "iostream"
using namespace std;

class A

{
int a;
public:
virtual void Fun(int n)
{
a = n;
cout<<"This is in A : "<<a<<endl;
}
};
class B : public A

{
int b;
public:
virtual void Fun(int n)
{
b = n;
cout<<"This is in B : "<<b<<endl;
}
};
class C : public A

{
int c;
public:
virtual void Fun(int n)
{
c = n;
cout<<"This is in C : "<<c<<endl;
}
};
class D : public B, public C

{
int d;
public:
virtual void Fun(int n)
{
d = n;
cout<<"This is in D : "<<d<<endl;
}
};

int main()

{
D d;
d.Fun(3);
return 0;
}
鍏堟潵鐪嬬湅澶氶噸緇ф壙鐨勫璞$粍緇囩殑緇撴瀯
瀹為檯涓婏紝澶氶噸緇ф壙vc閮藉皢瀹冭В閲婁負榪欎釜緇撴瀯銆備絾鏄閲嶉泦鎴愪腑瀹為檯鍦ㄥ唴瀛樹腑鐨勭粍緇囨槸寰堜笉涓鏍風殑
00B606D8 0046F020 offset test3.D::`vftable'
00B606DC CDCDCDCD A::a
00B606E0 CDCDCDCD B::b
00B606E4 0046F01C offset test3.D::`vftable'
00B606E8 CDCDCDCD A::a
00B606EC CDCDCDCD C::c
00B606F0 CDCDCDCD D::d
note:
鎸夌収閬撶悊鏉ヨ涓や釜offset test3.D::`vftable'搴旇鎸囧悜鍚屼竴涓湴鏂規墠瀵癸紝鍙繖閲屾槸錛?br>
絎簩涓猳ffset test3.D::`vftable'鎸囧悜鐨勪綅緗槸絎簩綃囪榪囩殑璺寵漿鍑芥暟錛?br>
2.铏氱戶鎵?br>
#include "iostream"
using namespace std;

class A

{
int a;
public:
virtual void Fun(int n)
{
a = n;
cout<<"This is in A : "<<a<<endl;
}
};
class B : virtual public A

{
int b;
public:
virtual void Fun(int n)
{
b = n;
cout<<"This is in B : "<<b<<endl;
}
};
class C :virtual public A

{
int c;
public:
virtual void Fun(int n)
{
c = n;
cout<<"This is in C : "<<c<<endl;
}
};
class D : public B, public C

{
int d;
public:
virtual void Fun(int n)
{
d = n;
cout<<"This is in D : "<<d<<endl;
}
};

int main()

{
D *pd = new D;
pd->Fun(sizeof(D));
return 0;
}
00A806D8 0046F02C offset test3.D::`vbtable'
00A806DC CDCDCDCD B::b
00A806E0 0046F020 offset test3.D::`vbtable'
00A806E4 CDCDCDCD C::c
00A806E8 CDCDCDCD A::a
00A806EC 0046F01C offset test3.D::`vftable'
00A806F0 CDCDCDCD D::d
絎竴鍜岀浜屼釜offset test3.D::`vbtable' 鎸囧悜涓涓亸縐昏煩杞〃錛屽畠鐨勮〃涓敤鍋忕Щ鎸囧悜浜嗙湡姝g殑offset test3.D::`vbtable'錛岀涓変釜鏄湡姝g殑offset test3.D::`vbtable'鍦板潃
0046F01C >004011A9 test3.004011A9 絎笁涓猳ffset test3.D::`vbtable'
0046F020 >00000000 絎簩涓猳ffset test3.D::`vbtable'
0046F024 0000000C 鍋忕ЩC
0046F028 00000000
0046F02C >00000000 絎竴涓猳ffset test3.D::`vbtable'
0046F030 00000014 渚垮疁14
#include<iostream>
using namespace std;

class A
{
public:
virtual void fun1()
{ cout<<"A::fun1"<<endl;}
virtual void fun2()
{cout<<"A::fun2"<<endl;}
};

class B : public A

{
public: 
virtual void fun1()
{ cout<<"B::fun1"<<endl;}
virtual void fun2()
{cout<<"B::fun2"<<endl;}
};

void main()
{
void (A::*f1)();
void (A::*f2)();
A *p=new B;
f1 = &A::fun1;
f2 = &A::fun2;
(p->*f1)();
(p->*f2)();
printf("f1 = %p f2 = %p\n", f1, f2);
printf("B::fun1 = %p, B::fun2 = %p\n", &A::fun1, &A::fun2);
delete p;
system("pause");
}
0040121E . C745 F0 AA104>mov dword ptr [ebp-10], 004010AA
00401225 . C745 EC B4104>mov dword ptr [ebp-14], 004010B4
0040122C . 8BF4 mov esi, esp
0040122E . 8B4D E8 mov ecx, [ebp-18]
00401231 . FF55 F0 call [ebp-10]
00401234 . 3BF4 cmp esi, esp
00401236 . E8 A5870000 call _chkesp
0040123B . 8BF4 mov esi, esp
0040123D . 8B4D E8 mov ecx, [ebp-18]
00401240 . FF55 EC call [ebp-14]
00401243 . 3BF4 cmp esi, esp
00401245 . E8 96870000 call _chkesp
0040124A . 8B55 EC mov edx, [ebp-14]
0040124D . 52 push edx ; /<%p>
0040124E . 8B45 F0 mov eax, [ebp-10] ; |
00401251 . 50 push eax ; |<%p>
00401252 . 68 48404300 push 00434048 ; |format = "f1 = %p f2 = %p",LF,""
00401257 . E8 14820000 call printf ; \printf
0040125C . 83C4 0C add esp, 0C
0040125F . 68 B4104000 push 004010B4 ; /<%p> = Cplusplu.004010B4
00401264 . 68 AA104000 push 004010AA ; |<%p> = Cplusplu.004010AA
00401269 . 68 24404300 push 00434024 ; |format = "B::fun1 = %p, B::fun2 = %p",LF,""
0040126E . E8 FD810000 call printf ; \printf
00402300 > > \8B01 mov eax, [ecx] // 絎竴涓櫄鍑芥暟
00402302 . FF20 jmp [eax]
00402304 CC int3
00402305 CC int3
00402306 CC int3
00402307 CC int3
00402308 CC int3
00402309 CC int3
0040230A CC int3
0040230B CC int3
0040230C CC int3
0040230D CC int3
0040230E CC int3
0040230F CC int3
00402310 > > 8B01 mov eax, [ecx] // 絎簩涓櫄姹楁暟
00402312 . FF60 04 jmp [eax+4]
00401019 |> \33F6 xor esi, esi
0040101B |> 8BCE mov ecx, esi
0040101D |. E8 5E060000 call 00401680
00401022 |. 8BCE mov ecx, esi
00401024 |. E8 67060000 call 00401690
00401029 |. 68 90164000 push 00401690 ; Entry address
0040102E |. 68 80164000 push 00401680 ; Entry address
00401033 |. 68 C4F04000 push 0040F0C4 ; ASCII "f1 = %p f2 = %p",LF
00401038 |. E8 2D310000 call 0040416A
0040103D |. 83C4 0C add esp, 0C
00401040 |. 68 90164000 push 00401690 ; Entry address
00401045 |. 68 80164000 push 00401680 ; Entry address
0040104A |. 68 A8F04000 push 0040F0A8 ; ASCII "B::fun1 = %p, B::fun2 = %p",LF
0040104F |. E8 16310000 call 0040416A
00401680 $ 8B01 mov eax, [ecx]
00401682 . FF20 jmp [eax]
00401684 CC int3
00401685 CC int3
00401686 CC int3
00401687 CC int3
00401688 CC int3
00401689 CC int3
0040168A CC int3
0040168B CC int3
0040168C CC int3
0040168D CC int3
0040168E CC int3
0040168F CC int3
00401690 $ 8B01 mov eax, [ecx]
00401692 . FF60 04 jmp [eax+4]

#include "iostream"
using namespace std;
class C

{
public:
int c;
virtual void display(int s);
};
void C::display(int s)

{
c = 3;
cout<<"this is in C:"<<s<<" "<<c<<endl;
}
class D : public C

{
public:
int d;
void display(int s);
};
void D::display(int s)

{
d = 4;
cout<<"this is in d:"<<s<<" "<<d<<endl;
}
void main()

{
C c;
c.display(sizeof(c));
C *d = (C *)new D;
d->display(sizeof(d));
}
.text:00401890 ; Attributes: bp-based frame
.text:00401890
.text:00401890 C__C proc near ; CODE XREF: j_C__Cj
.text:00401890
.text:00401890 var_44 = dword ptr -44h
.text:00401890 var_4 = dword ptr -4
.text:00401890
.text:00401890 push ebp
.text:00401891 mov ebp, esp
.text:00401893 sub esp, 44h
.text:00401896 push ebx
.text:00401897 push esi
.text:00401898 push edi
.text:00401899 push ecx
.text:0040189A lea edi, [ebp+var_44]
.text:0040189D mov ecx, 11h
.text:004018A2 mov eax, 0CCCCCCCCh
.text:004018A7 rep stosd
.text:004018A9 pop ecx
.text:004018AA mov [ebp+var_4], ecx
.text:004018AD mov eax, [ebp+var_4]
.text:004018B0 mov dword ptr [eax], offset ??_7C@@6B@ ; const C::`vftable'
.text:004018B6 mov eax, [ebp+var_4]
.text:004018B9 pop edi
.text:004018BA pop esi
.text:004018BB pop ebx
.text:004018BC mov esp, ebp
.text:004018BE pop ebp
.text:004018BF retn
.text:004018BF C__C endp
.text:004018E9 pop ecx
.text:004018EA mov [ebp+var_4], ecx
.text:004018ED mov ecx, [ebp+var_4]
.text:004018F0 call j_C__C //鍒濆鍖栫埗綾?br>
.text:004018F5 mov eax, [ebp+var_4]
.text:004018F8 mov dword ptr [eax], offset ??_7D@@6B@ ; const D::`vftable'
.text:004018FE mov eax, [ebp+var_4] // 灝嗗啓鑷繁鐨勮〃
#include "iostream"
using namespace std;
struct A

{
int a;
void display(int s);
};
void A::display(int s)

{
a = 1;
cout<<"this is in A:"<<s<<" "<<a<<endl;
}
class B

{
public:
int b;
void display(int s);
};
void B::display(int s)

{
b = 2;
cout<<"this is in B:"<<s<<" "<<b<<endl;
}
void main()

{
A a;
a.display(sizeof(a));
B b;
b.display(sizeof(b));
}
.text:00401820 main proc near ; CODE XREF: _mainj
.text:00401820
.text:00401820 var_48 = dword ptr -48h
.text:00401820 var_8 = dword ptr -8
.text:00401820 var_4 = dword ptr -4
.text:00401820
.text:00401820 push ebp
.text:00401821 mov ebp, esp
.text:00401823 sub esp, 48h
.text:00401826 push ebx
.text:00401827 push esi
.text:00401828 push edi
.text:00401829 lea edi, [ebp+var_48]
.text:0040182C mov ecx, 12h
.text:00401831 mov eax, 0CCCCCCCCh
.text:00401836 rep stosd
.text:00401838 push 4
.text:0040183A lea ecx, [ebp+var_4]
.text:0040183D call j_A__display
.text:00401842 push 4
.text:00401844 lea ecx, [ebp+var_8]
.text:00401847 call j_B__display
.text:0040184C pop edi
.text:0040184D pop esi
.text:0040184E pop ebx
.text:0040184F add esp, 48h
.text:00401852 cmp ebp, esp
.text:00401854 call __chkesp
.text:00401859 mov esp, ebp
.text:0040185B pop ebp
.text:0040185C retn
.text:0040185C main endp
.text:00401140 ; int __cdecl main(int argc,const char **argv,const char *envp)
.text:00401140 _main proc near ; CODE XREF: start+AFp
.text:00401140
.text:00401140 var_8 = dword ptr -8
.text:00401140 var_4 = dword ptr -4
.text:00401140 argc = dword ptr 4
.text:00401140 argv = dword ptr 8
.text:00401140 envp = dword ptr 0Ch
.text:00401140
.text:00401140 sub esp, 8
.text:00401143 lea ecx, [esp+8+var_8]
.text:00401147 push 4
.text:00401149 call sub_401000
.text:0040114E push 4
.text:00401150 lea ecx, [esp+0Ch+var_4]
.text:00401154 call sub_4010A0
.text:00401159 add esp, 8
.text:0040115C retn
.text:0040115C _main endp