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

后端 未结 7 1753
旧时难觅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

    Scott Meyers' book, Effective C++, has several items related to this topic. I would definitely check out the item titled, "Don't try to return a reference when you must return an object." This is item #23 in the 1st or 2nd editions, or #21 in the 3rd edition.

提交回复
热议问题