天下

记录修行的印记

再学C++98 构造函数

#include "stdafx.h"
class Test
{
public:
    
int _a;
    Test(
int a) : _a(a) {}
    Test()
    {
        
this->Test::Test(0); //结果正确
        Test(0); //结果错误,_a 随机
        *this = Test(0); //正确,但产生临时对象
    }
};




int _tmain(int argc, _TCHAR* argv[])
{
    Test obj;
    printf(
"%d \r\n",obj._a);
    
return 0;
}


this->Test::Test(0); //汇编
    {
        
this->Test::Test(0);
00BD1483  push        
0  
00BD1485  mov         ecx,dword ptr [
this]  
00BD1488  call        Test::Test (0BD101Eh)  

    }
    
   
   
Test(
0);//汇编 
    {
        Test(0);
00031483  push        0  
00031485  lea         ecx,[ebp-0D4h]  
0003148B  call        Test::Test (3101Eh)  
    }    

posted on 2016-08-12 15:30 天下 阅读(234) 评论(0)  编辑 收藏 引用 所属分类: C/C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2012年12月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

导航

统计

常用链接

留言簿(4)

随笔分类(378)

随笔档案(329)

链接

最新随笔

搜索

最新评论