关于c++拷贝构造函数

#include <iostream>
using namespace std;

class Test{
public :
      Test(){
            cout << "Hello world !" << endl;
        }           
}    ;

int main(){
    Test a;
    Test b=a;

   return 0; 
}

 

 

输出只有一个  Hello world !

第一个Test t;自动调用构造函数 Test();,而Test t1=t;则是用t初始化t1 ,调用的是Test的默认拷贝构造函数,所以不会输出hello world。

http://q.cnblogs.com/q/55372/ 

posted on 2013-10-03 10:11  我勒个去~  阅读(48)  评论(0编辑  收藏  举报

导航