返回值优化

mark一下代码 后续补充,要点是gcc编译器的rvo优化和-fno-elide-constructors编译参数

/*
 * =====================================================================================
 *
 *       Filename:  test.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  20160529213021 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  
 *   Organization:  
 *
 * =====================================================================================
 */
#include 
#include 

using namespace std;

class A
{
    public:
    A(){cout << "call A" <;}
    A(const A &a){c = a.c;cout << "call copy A " <
//  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 " <;
    return 0;
}

你可能感兴趣的:(linux编程)