Avoiding copy of objects with the “return” statement

前端 未结 7 2181
慢半拍i
慢半拍i 2020-11-27 16:16

I have a very basic question in C++. How to avoid copy when returning an object ?

Here is an example :

std::vector test(const uns         


        
相关标签:
7条回答
  • 2020-11-27 16:43

    Compilers often can optimize away the extra copy for you (this is known as return value optimization). See https://isocpp.org/wiki/faq/ctors#return-by-value-optimization

    0 讨论(0)
提交回复
热议问题