Store return value of function in reference C++

后端 未结 3 481
星月不相逢
星月不相逢 2020-12-12 18:01

Is it valid to store the return value of an object in a reference?

class A { ... };
A myFunction()
{
    A myObject;
    return myObject;
} //myObject goes o         


        
3条回答
  •  温柔的废话
    2020-12-12 18:41

    You might be interested in the return-by-value optimization that many compilers make to avoid calling the copy constructor.

提交回复
热议问题