Prefer to pass or return reference.It will avoid extra copy constructor calling
and more efficient. But if you create a obj inside of a function, you cannot
return reference of it. You have to return value of it. see effective C++ item
22 and 23.
A const object reference passed into a function, if you want to return it , it
must be const too.
Only const reference can bound to temporary. temporary is not lvalue, and
only lvalue can bound to reference to non-const. And only stack-base const
reference can work in this way. If a const reference is class member, it can’t
work.
A const reference can prolong temporary variable. See two examples below:
Another const reference example is copy ctor: For a class with a lot
allocated resource, please use move copy ctor which explained in the next
section: