小记:运行环境: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:角落里的一条狗