很有意思的现象,关于复制构造函数
// test.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"using namespace std;class A{public: A(int i) { value = i; cout << "Ordinary now value = " << value << endl; } A(const A & other) { if(this == &other) { return; } value = other.value + 1;//复制时加一,这样看出是生成哪个对象调用的 cout << "Copy fun now value =" << value << endl; } ~A() { cout << "destroy value =" << value << endl; } int getValue() { return value; }private: int value;};int _tmain(int argc, _TCHAR* argv[]){ for(int i = 0;i < 1;i++) { A a(A(A(A(A(5)))));//这一句很猛的,试过了,括号里有4个A()那么一定调用2次,6个的话会调用3次 //就是A()的个数除以2次 cout << a.getValue() << endl; } cin.get(); return 0;}