Whenever you pass an address to a function, you should modify it as const as you can .
/*** book: "thinkinginc++" * function: On the role of const on function return value * Time: September 7, 2014 14:14:57* Author: cutter_point*/class x{ int i;public: X (int ii=0); void modify ();}; x::x (int ii) { i=ii;} void X::modify () { i++;} X f5 () { return x ();//An object, the default constructor, returns an lvalue that can be assigned to modify}const x f6 () { return x ();//return the const type of}void F7 (x& X) { C10/>x.modify ();} int main () { F5 () =x (1); F5 (). modify (); //! F7 (F5 ()); Here is the reference, C + + cannot be compiled by the reason that parameter passing will establish a replica //! f6 () =x (1); Returns a const type that cannot change the value of //! f6 (). modify (); //! F7 (f6 ()); Here the argument is a reference, not a const reference to return 0;}
"Thinkinginc++" 40, on the effect of const on function return value