- UID
- 2198
注册时间2005-6-29
阅读权限255
最后登录1970-1-1
副坛主
该用户从未签到
|
楼主 |
发表于 2010-1-19 10:37:35
|
显示全部楼层
拷贝构造中初始化类表的顺序
1. 先看一下Copy构造
public:
char * m_pName;
int m_nAge;
int m_nHeight;
34:
35: People::People(const People &obj):m_nAge(obj.m_nAge),
36: m_pName(obj.m_pName),m_nHeight(obj.m_nHeight)
37: {
00411850 push ebp
00411851 mov ebp,esp
00411853 sub esp,44h
00411856 push ebx
00411857 push esi
00411858 push edi
00411859 push ecx
0041185A lea edi,[ebp-44h]
0041185D mov ecx,11h
00411862 mov eax,0CCCCCCCCh
00411867 rep stos dword ptr [edi]
00411869 pop ecx
// 从这里开始 配对COPY ~
0041186A mov dword ptr [ebp-4],ecx
0041186D mov eax,dword ptr [ebp-4]
00411870 mov ecx,dword ptr [ebp+8]
00411873 mov edx,dword ptr [ecx+4]
00411876 mov dword ptr [eax+4],edx
00411879 mov eax,dword ptr [ebp-4]
0041187C mov ecx,dword ptr [ebp+8]
0041187F mov edx,dword ptr [ecx+8]
00411882 mov dword ptr [eax+8],edx
00411885 mov eax,dword ptr [ebp-4]
00411888 mov ecx,dword ptr [ebp+8]
0041188B mov edx,dword ptr [ecx+0Ch]
0041188E mov dword ptr [eax+0Ch],edx
00411891 mov eax,dword ptr [ebp-4]
00411894 mov dword ptr [eax],offset People::`vftable' (00428038)
38: // 拷贝构造中只默认添加一个虚表的写入操作
39: // 先写虚表 再复制
40: // m_nAge = obj.m_nAge;
41: // m_nHeight = obj.m_nAge;
42: // m_pName = obj.m_pName;
43: }
0041189A mov eax,dword ptr [ebp-4]
0041189D pop edi
0041189E pop esi
0041189F pop ebx
004118A0 mov esp,ebp
004118A2 pop ebp
004118A3 ret 4
2.拷贝构造确实是按老师说的 不管初始化类表如何 都按照类的定义顺序来赋值
People::People(int age,int heigth,char * pName):m_nAge(age),
m_nHeight(heigth),m_pName(pName)
004013D9 pop ecx
004013DA mov dword ptr [ebp-4],ecx
004013DD mov eax,dword ptr [ebp-4]
004013E0 mov ecx,dword ptr [ebp+10h]
004013E3 mov dword ptr [eax+4],ecx
004013E6 mov edx,dword ptr [ebp-4]
004013E9 mov eax,dword ptr [ebp+8]
004013EC mov dword ptr [edx+8],eax
004013EF mov ecx,dword ptr [ebp-4]
004013F2 mov edx,dword ptr [ebp+0Ch]
004013F5 mov dword ptr [ecx+0Ch],edx |
|