Question
C++ function return reference
Why is it that I cannot/shouldn't return the reference to a local variable to a function? Is it because the temporary variable is automatically destroyed after the function finishes executing?
const string & wrap(string & s1, const string & s2){
string temp;
temp = s2 + s1 + s2;
return temp;
}
What about this one:
const string & wrap2(const string & s1, const string & s2){
return (s2 + s1 + s2);
}