小编Ham*_*son的帖子

返回前RVO覆盖参数值

在AIX上使用xlC编译以下内容会导致打印"2 2"的代码.在使用gcc和clang的Linux上,它可靠地生成"3 3".

#include <iostream>

struct Numbers
{
    Numbers() : a(0) , b(0) { } 
    Numbers(int a, int b) : a(a), b(b) { }

    int a;
    int b;
};

Numbers combine(const Numbers& a, const Numbers& b)
{
    Numbers x;
    x.a = a.a + b.a;
    x.b = a.b + b.b;
    return x;
}

Numbers make()
{
    Numbers a(1, 1);
    Numbers b(2, 2);

    a = combine(a, b);
    return a;
}

int main()
{
    Numbers a = make();
    std::cerr << a.a << " …
Run Code Online (Sandbox Code Playgroud)

c++ language-lawyer c++03

10
推荐指数
1
解决办法
155
查看次数

标签 统计

c++ ×1

c++03 ×1

language-lawyer ×1