#include<iostream>
using namespace std;
class point3d;
class point2d;
class point3d
{
private:int x; int y; int z;
public:
point3d(int a = 0, int b = 0, int c = 0) :x(a), y(b), z(c) {}
};
class point2d
{
int a;
int b;
public:
point2d(int x=0,int y=0):a(x),b(y){}
operator point3d()
{
return{ a,b,0 };
}
};
int main()
{
point2d z;
point3d q = z;
return 0;
}
反匯編后
point 2d z:(將調用構造函數
push 0(壓入2個參數罷了)
push 0
lea ecx,[z] (將z對象的地址保存到ecx中)
call point2d::point2d (0C01348h)
mov dword ptr [this],ecx .將ecx(z對象的地址).保存到this指針當中
mov eax,dword ptr [this] .將z對象的地址賦給eax
mov ecx,dword ptr [x]; 將變量x的值取出來保存到ecx中
mov dword ptr [eax],ecx..將ecx=0賦給對象z的低4位(也就是a)
mov eax,dword ptr [this].將對象的地址賦給eax
mov ecx,dword ptr [y] 將變量y的值給ecx
mov dword ptr [eax+4],ecx 將y的值賦給高4位對象的地址(也就是b)
mov eax,dword ptr [this],將對象的地址給eax作為返回值
point3d q =z;
008538B4 lea eax,[q] ;將q的地址賦給eax
008538B7 push eax ;壓棧.作為參數
008538B8 lea ecx,[z] ;將z的地址賦給ecx
008538BB call point2d::operator point3d (085133Eh)
00853380 push ebp
00853381 mov ebp,esp
00853383 sub esp,0CCh
00853389 push ebx
0085338A push esi
0085338B push edi
0085338C push ecx
0085338D lea edi,[ebp-0CCh]
00853393 mov ecx,33h
00853398 mov eax,0CCCCCCCCh
0085339D rep stos dword ptr es:[edi]
0085339F pop ecx ;
008533A0 mov dword ptr [this],ecx ;將 point2d z的地址賦給了this指針
return{ a,b,0 };
008533A3 push 0 ;0壓棧
008533A5 mov eax,dword ptr [this]
008533A8 mov ecx,dword ptr [eax+4] ;將z的a變量的值賦給ecx
008533AB push ecx ;ecx壓棧
008533AC mov edx,dword ptr [this]
008533AF mov eax,dword ptr [edx] ;將a的值賦給了eax中
008533B1 push eax ;eax壓棧
008533B2 mov ecx,dword ptr [ebp+8] ;取出q的地址
008533B5 call point3d::point3d (0851357h) ;point3d(一個q的地址.參數.3個變量參數)
008533BA mov eax,dword ptr [ebp+8] ;將q的地址取出來.作為返回值
}