首页 > 其他 > 详细

复制构造和赋值构造的一些尝试

时间:2014-08-23 15:17:01      阅读:202      评论:0      收藏:0      [点我收藏+]

小记:运行环境:vs 2013 c++ win32 console application


#include "stdafx.h"

#include <iostream>

#include <cstdlib>

using namespace std;

class A{

public:

    A(){ cout << "A::A()" << endl; }

    A(A&){ cout << "A::A(A&)" << endl; }

    A& operator=(A& a)
    { cout << "operator=(A&)" << endl;
//    *this = a;        // endless loop
    return *this; }

};



int  _tmain(int argc, _TCHAR* argv[])

{

//    A a, b;        // two default constructor
//    a = b;        // one assignment

//    A a;        // one default constructor
//    A b = a;    // one copy constructor

    A c = A();        // one default constructor, no temporary project

    system("pause");
    return 0;

}

 

Author:角落里的一条狗

Email:benjamin123go@gmail.com

复制构造和赋值构造的一些尝试

原文:http://www.cnblogs.com/Bejadin/p/3931081.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!