c++类研究(1)普通的c++类_0

2019-10-17 00:51:25 来源: 万州信息港

#include <iostream.h>

class cppclass

{

private:

int i;

public:

cppclass();

void cppout();

};

cppclass::cppclass()

{

i=5;

}

void cppclass::cppout()

{

cout<<i;

}

void main()

{

cppclass a;

a.cppout();

}

@ILT+0(??0cppclass@@QAE@XZ):

00401005 E9 26 00 00 00 jmp cppclass::cppclass (00401030)

@ILT+5(?cppout@cppclass@@QAEXXZ):

0040100A E9 61 00 00 00 jmp cppclass::cppout (00401070)

@ILT+10(_main):

0040100F E9 AC 00 00 00 jmp main (004010c0)

1: #include <iostream.h>

2: class cppclass

3: {

4: private:

5: int i;

6: public:

7: cppclass();

8: void cppout();

9: };

10: cppclass::cppclass()

11: {

00401030 55 push ebp

00401031 8B EC mov ebp,esp

00401033 83 EC 44 sub esp,44h

00401036 53 push ebx

00401037 56 push esi

00401038 57 push edi

00401039 51 push ecx

0040103A 8D 7D BC lea edi,[ebp-44h]

0040103D B9 11 00 00 00 mov ecx,11h

00401042 B8 CC CC CC CC mov eax,0CCCCCCCCh

00401047 F3 AB rep stos dword ptr [edi]

00401049 59 pop ecx

0040104A 89 4D FC mov dword ptr [ebp-4],ecx

12: i=5;

0040104D 8B 45 FC mov eax,dword ptr [ebp-4]

00401050 C7 00 05 00 00 00 mov dword ptr [eax],5

13: }

00401056 8B 45 FC mov eax,dword ptr [ebp-4]

00401059 5F pop edi

0040105A 5E pop esi

0040105B 5B pop ebx

0040105C 8B E5 mov esp,ebp

0040105E 5D pop ebp

0040105F C3 ret

14: void cppclass::cppout()

15: {

00401070 55 push ebp

00401071 8B EC mov ebp,esp

00401073 83 EC 44 sub esp,44h

00401076 53 push ebx

00401077 56 push esi

00401078 57 push edi

00401079 51 push ecx

0040107A 8D 7D BC lea edi,[ebp-44h]

0040107D B9 11 00 00 00 mov ecx,11h

00401082 B8 CC CC CC CC mov eax,0CCCCCCCCh

00401087 F3 AB rep stos dword ptr [edi]

00401089 59 pop ecx

0040108A 89 4D FC mov dword ptr [ebp-4],ecx

16: cout<<i;

0040108D 8B 45 FC mov eax,dword ptr [ebp-4]

00401090 8B 08 mov ecx,dword ptr [eax]

00401092 51 push ecx

00401093 B9 C0 89 42 00 mov ecx,offset cout (004289c0)

00401098 E8 73 00 00 00 call ostream::operator<< (00401110)

17: }

0040109D 5F pop edi

0040109E 5E pop esi

0040109F 5B pop ebx

004010A0 83 C4 44 add esp,44h

004010A3 3B EC cmp ebp,esp

004010A5 E8 B6 23 00 00 call __chkesp (00403460)

004010AA 8B E5 mov esp,ebp

004010AC 5D pop ebp

004010AD C3 ret

18: void main()

19: {

004010C0 55 push ebp

004010C1 8B EC mov ebp,esp

004010C3 83 EC 44 sub esp,44h

004010C6 53 push ebx

004010C7 56 push esi

004010C8 57 push edi

004010C9 8D 7D BC lea edi,[ebp-44h]

004010CC B9 11 00 00 00 mov ecx,11h

004010D1 B8 CC CC CC CC mov eax,0CCCCCCCCh

004010D6 F3 AB rep stos dword ptr [edi]

20: cppclass a;

004010D8 8D 4D FC lea ecx,[ebp-4]

004010DB E8 25 FF FF FF call @ILT+0(cppclass::cppclass) (00401005)

21: a.cppout();

004010E0 8D 4D FC lea ecx,[ebp-4]

004010E3 E8 22 FF FF FF call @ILT+5(cppclass::cppout) (0040100a)

22: }

004010E8 5F pop edi

004010E9 5E pop esi

004010EA 5B pop ebx

004010EB 83 C4 44 add esp,44h

004010EE 3B EC cmp ebp,esp

004010F0 E8 6B 23 00 00 call __chkesp (00403460)

004010F5 8B E5 mov esp,ebp

004010F7 5D pop ebp

004010F8 C3 ret

在main()函数运行时,创建类时跳转到了类的构建函数调用完返回!

通过例子可以看出,函数一直在调用类的成员函数,类在那儿进行初始化?

为此设计这样例子,

00401093 B9 C0 89 42 00 mov ecx,offset cout (004289c0)

00401098 E8 73 00 00 00 call ostream::operator<< (00401110)

004010E3 B9 C0 89 42 00 mov ecx,offset cout (004289c0)

004010E8 E8 23 00 00 00 call ostream::operator<< (00401110)

可以看到

004289c0 地址是初始化i的地址。

深圳男科医院哪家好
常德治疗白斑的医院
福建治疗输卵管堵塞方法
舟山治疗癫痫病医院
云南白斑疯医院
本文标签: