a=test.a;//2*this=test;}CTest&CTest:"">
#include "stdafx.h" class CTest { public: CTest(){}; CTest(const CTest &test); CTest& operator=(const CTest &test); public: int a; }; CTest::CTest(const CTest &test) { // 1 this->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; // 4 CTest test2 = test1; // 5 CTest test3; test3 = test1; return 0; }
this->a = test.a; return *this;