When should you return a reference to a object from a class method

后端 未结 7 1779
旧时难觅i
旧时难觅i 2021-02-14 01:14

What is the best practice for returning references from class methods. Is it the case that basic types you want to return without a reference whereas class objects you want to r

7条回答
  •  春和景丽
    2021-02-14 01:52

    Return basic types by value, except if you want to let the caller access the actual member.

    Return class objects (even std::string) by reference.

提交回复
热议问题