锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 緇撹錛?br>緙栬瘧鍣ㄤ笉鑳借嚜鍔ㄨ瘑鍒瀽鏋勫嚱鏁幫紝蹇呴』瑕佸鎬佺殑鏍囪瘑銆?/p>
#include <iostream>
using namespace std;
class CBase

{
public:
CBase()
{
cout<<"I in Base constructor"<<endl;
}
virtual ~CBase()
{
cout<<"I in Base deconstructor"<<endl;
}
};
class CDerived : public CBase

{
public:
CDerived()
{
cout<<"I in CDerived constructor"<<endl;
}
virtual ~CDerived()
{
cout<<"I in CDerived deconstructor"<<endl;
}
};

int main()

{
CBase *pBase = new CDerived();
delete pBase;
return 0;
}
杈撳嚭緇撴灉
I in Base constructor
I in CDerived constructor
I in CDerived deconstructor
I in Base deconstructor
浠ュ墠涓鐩磋寰梫irtual鐨勬寚瀹氭槸鍙湁鍙棤鐨勶紝鐜板湪鎵嶇煡閬擄紝濡傛灉涓嶅埗瀹歷irutal錛岄偅涔圛 in CDerived deconstructor灝變笉浼氳皟鐢ㄣ傝繖涓笌construtor瀹屽叏涓嶄竴鏍鳳紝浜嬪疄涓婁篃姝f槸榪欐牱鎶婁粬/瀹冨拷鐣ヤ簡銆?br>
鎺ョ潃灝辮鎯蟲兂濡備綍瀹炵幇鐨勫憿錛?br>
鍏堟潵鐪嬬湅鏋勯犲嚱鏁?br>004012CF . 894D F0 mov [ebp-10], ecx
004012D2 . 8B4D F0 mov ecx, [ebp-10]
004012D5 . E8 D0FDFFFF call 004010AA ; 璋冪敤鍩虹被鐨勬瀯閫犲嚱鏁?br>004012DA . C745 FC 00000>mov dword ptr [ebp-4], 0
004012E1 . 8B45 F0 mov eax, [ebp-10]
004012E4 . C700 3C204300 mov dword ptr [eax], offset CDerived::`vftable'
004012EA . 68 2D104000 push 0040102D
004012EF . 68 1C204300 push 0043201C ; ASCII "I in CDerived constructor"
004012F4 . 68 40954300 push offset std::cout
004012F9 . E8 CAFDFFFF call 004010C8
鍜屼互鍓嶇悊瑙g殑涓鏍鳳紝涓嶅瑙i噴
涓嬮潰鏄瀽鏋勫嚱鏁?娉ㄦ剰榪欓噷鏄疌Derived鐢熸垚鐨刣elete鍑芥暟鍝?
00401069 . /E9 32040000 jmp CDerived::`scalar deleting destructor'
004014BA |. 894D FC mov [ebp-4], ecx
004014BD |. 8B4D FC mov ecx, [ebp-4]
004014C0 |. E8 F9FBFFFF call 004010BE ; 璋冪敤瀛愮被鐨勬瀽鏋勫嚱鏁?br>004014C5 |. 8B45 08 mov eax, [ebp+8]
004014C8 |. 83E0 01 and eax, 1
004014CB |. 85C0 test eax, eax
004014CD |. 74 0C je short 004014DB
004014CF |. 8B4D FC mov ecx, [ebp-4]
004014D2 |. 51 push ecx ; /Arg1
004014D3 |. E8 A8130000 call operator delete ; \operator delete
0040153F . 894D F0 mov [ebp-10], ecx
00401542 . 8B45 F0 mov eax, [ebp-10]
00401545 . C700 3C204300 mov dword ptr [eax], offset CDerived::`vftable'
0040154B . C745 FC 00000>mov dword ptr [ebp-4], 0
00401552 . 68 2D104000 push 0040102D
00401557 . 68 80204300 push 00432080 ; ASCII "I in CDerived disconstructor"
0040155C . 68 40954300 push offset std::cout
00401561 . E8 62FBFFFF call 004010C8
00401566 . 83C4 08 add esp, 8
00401569 . 8BC8 mov ecx, eax
0040156B . E8 1CFBFFFF call 0040108C
00401570 . C745 FC FFFFF>mov dword ptr [ebp-4], -1
00401577 . 8B4D F0 mov ecx, [ebp-10]
0040157A . E8 E0FAFFFF call 0040105F ; 鍩虹被鐨勬瀽鏋勫嚱鏁?/p>
]]>
reference : http://blog.csdn.net/china8848/archive/2008/03/29/2227131.aspx
source :
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
int n,m;
char DNA[100][100] =
{0};
int calc_unsortedness(const char *pDNA, int length)

{
int i;
char a;
int left_C = 0, left_G = 0, left_T = 0;
int count = 0;
for(i = length-1; i >= 0; i--)
{
a = pDNA[i];
switch(a)
{
case 'A':
left_C++;
left_G++;
left_T++;
break;
case 'C':
left_G++;
left_T++;
count+=left_C;
break;
case 'G':
left_T++;
count+=left_G;
break;
case 'T':
count+=left_T;
break;
}
}
return count;
}
int compare(const void *arg1, const void *arg2)

{
return calc_unsortedness((const char *)arg1, n) - calc_unsortedness((const char *)arg2, n);
}
int main()

{
int i;
scanf("%d %d\n", &n, &m);
//memset(DNA, 0, sizeof(DNA));
for (i = 0; i < m; ++i)
gets(DNA[i]);
qsort((void *)DNA, m, sizeof(char) * 100, compare);
for (i = 0; i < m; ++i)
puts(DNA[i]);
return 0;
}

濂戒箙娌″仛棰樹簡錛屼粖澶╁洖鏉ュ緱鏃┿傚氨鎶婂墠鍑犲ぉ鐪嬩簡鐨勮繖棰樼粰瀹炵幇浜嗐侫C鐨勫巻紼嬪緢濂囨?br>
棣栧厛鏄痠nclude浜?lt;search.h> 錛岀粨鏋? CE
鎺ョ潃鏄悶閿欎簡n鍜宮錛屾妸DNA瀹氫箟涓?char DNA[50][100] 緇撴灉 : RTE
鐒跺悗灝嗕粬浠掍簡榪囨潵,灝卞彉鎴愪簡OLE
鐧炬濅笉寰楀叾瑙o紝鏈鍚庡畾涔塩har DNA[100][100]錛屽氨AC浜?
#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