Returning Large Objects in Functions

后端 未结 9 1231
無奈伤痛
無奈伤痛 2020-11-27 14:17

Compare the following two pieces of code, the first using a reference to a large object, and the second has the large object as the return value. The emphasis on a \"large o

9条回答
  •  一向
    一向 (楼主)
    2020-11-27 14:48

    Use the second approach. It may seem that to be less efficient, but the C++ standard allows the copies to be evaded. This optimization is called Named Return Value Optimization and is implemented in most current compilers.

提交回复
热议问题