char*[] object can be passed to function version2() & version 3() by the const reference, which means s2 is a temporary object equals to "###" or "@@@".
But why the temporary object s2 can be returned back, while the temporary object temp cannot.
int main()
{
    result = version2(input, "###");
    cout << "Your string enhanced: " << result << endl;
    result = version3(input, "@@@");
    cout << "Your string enhanced: " << result << endl;
    return 0;
}
// No Error
const string & version2(string & s1, const string & s2)
{
    return s2; 
}
// Error
const string & version3(string & s1, const string & s2)
{
    string temp = s2 + s1 + s2;
    return temp;
}
 
     
     
    