Plz explain difference between functions returning ref
Check out this example:
When I compile this, I only get the warning for "reference to local variable 'f' returned" when fn1() is called.
foo* f_ptr = new foo();
foo& f_ref = fn1(); // Compiler warning here
foo& f_ref2 = fn2();
What's the difference between fn1() and fn2(), besides the obvious use of a foo pointer in fn2()?
Why do I only get the warning for fn1()?
Isn't fn2() returning a reference to a local variable as well?