IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    再学C++98 构造函数

    天下发表于 2016-08-12 07:30:00
    love 0
    #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)  
        }    


    天下 2016-08-12 15:30 发表评论


沪ICP备19023445号-2号
友情链接