return by reference - which of the two is the correct one

Posted by eriks on Stack Overflow See other posts from Stack Overflow or by eriks
Published on 2010-03-24T11:56:32Z Indexed on 2010/03/24 12:03 UTC
Read the original article Hit count: 253

Filed under:

i have the function: const A& f(...) {...}

a. const A a1 = f(..);
b. const A &a2 = f(...);

which of the is the better one to use? in both cases, if i understand correctly, i prevent the possibility of modifying the returned object. in the first option, the copy constructor of A will be called - am i correct?

© Stack Overflow or respective owner

Related posts about c++