C++拷贝构造函数和赋值构造函数中的问题
关于C++的拷贝构造函数和赋值构造函数,有如下代码:
#include "stdafx.h"class CTest{public:CTest(){};CTest(const CTest &test);CTest& operator=(const CTest &test);public:int a;};CTest::CTest(const CTest &test){// 1this->a = test.a;// 2*this = test;}CTest& CTest::operator=(const CTest &test){if (&test == this)return *this;// 3*this = test;return *this;}int _tmain(int argc, _TCHAR* argv[]){CTest test1;test1.a = 10;CTest *pTest = new CTest(test1);delete pTest;// 4CTest test2 = test1;// 5CTest test3;test3 = test1;return 0;}
this->a = test.a;return *this;