mark一下代码 后续补充,要点是gcc编译器的rvo优化和-fno-elide-constructors编译参数
/*
* =====================================================================================
*
* Filename: test.cpp
*
* Description:
*
* Version: 1.0
* Created: 2016年05月29日 21时30分21秒
* Revision: none
* Compiler: gcc
*
* Author:
* Organization:
*
* =====================================================================================
*/
#include <stdlib.h>
#include <iostream>
using namespace std;
class A
{
public:
A(){cout << "call A" <<endl;}
A(const A &a){c = a.c;cout << "call copy A " <<endl;}
// A operator =(const A &a){c = a.c;cout << "call =====A " << endl;}
~A(){cout << "call ~A " << endl;}
int c;
};
A GetObj()
{
A a;
a.c = 100;
cout << "IN GetObj" << endl;
return a;
}
void SetObj(A a)
{
}
int main()
{
cout << "before " << endl;
//A a = GetObj();
A a;
cout << "++++++++" << endl;
// A b = a;
//a = b;
SetObj(a);
// b = GetObj();
// A c (GetObj());
//a = GetObj();
//GetObj();
//A a;
//a = GetObj();
//cout << "a = " << a.c << endl;
//A b(a);
//A b;
//b.c = 1000;
//A d = b;
//d = b;
//A a(GetObj());
// GetObj();
// cout << "a = " << a.c << endl;
//A b(a);
// A b(a);
cout << "After " <<endl;
return 0;
}