How to return a class object by reference in C++?

后端 未结 5 1457
北恋
北恋 2020-12-07 20:53

I have a class called Object which stores some data.

I would like to return it by reference using a function like this:

    Object& return_Object         


        
5条回答
  •  醉梦人生
    2020-12-07 21:44

    You can only return non-local objects by reference. The destructor may have invalidated some internal pointer, or whatever.

    Don't be afraid of returning values -- it's fast!

提交回复
热议问题