C++: returning by reference and copy constructors

后端 未结 9 1797
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 09:46

References in C++ are baffling me. :)

The basic idea is that I\'m trying to return an object from a function. I\'d like to do it without returning a pointer (because

9条回答
  •  一生所求
    2020-12-09 10:01

    The best way to understand copying in C++ is often NOT to try to produce an artificial example and instrument it - the compiler is allowed to both remove and add copy constructor calls, more or less as it sees fit.

    Bottom line - if you need to return a value, return a value and don't worry about any "expense".

提交回复
热议问题