拷贝构造函数

1.标准格式:X::(const X &)

2.使用情况 :A:当用一个对象去初始化同类的一个对象时

      B:作为函数形参

      C:作为函数返回值

3.易错点:

#include<iostream>

using namespace std;

class Test
{
    
};

int main()
{
      Test t1;
      Test t2(t1);
      Test t3;
      t3=t1;//不调用拷贝构造函数,只复制对应值
      return 0;    
}

 

posted @ 2019-04-04 19:50  -Asurada-  阅读(163)  评论(0编辑  收藏  举报