Returning an object in C++

前端 未结 5 936
一整个雨季
一整个雨季 2021-02-14 12:02

I am learning C++ from a background of mostly C and Java and I am curious on what is the best way to return an object in C++ without having to copy the object. From my understa

5条回答
  •  自闭症患者
    2021-02-14 12:36

    Rvalue refernces will be much faster, as they are an intrinsic language feature, rather than a reference counting class. Using a smart or shared pointer here will give no gain, and greatly decrease clarity. However, the rvalue references are a part of the language designed for this kind of thing. Use the rvalue reference.

提交回复
热议问题