C++ function return reference
<p>Here goes another n00b question:</p>

<p>Why is it that I cannot/shouldn't return the referece to a local variable to a function? Is it because the temporary variable is automatically destroyed after the function finishes executing?</p>

<pre><code>const string &amp; wrap(string &amp; s1, const string &amp; s2){
    string temp;
    temp = s2 + s1 + s2;
    return temp;
}
</code></pre>

<p>What about this one:</p>

<pre><code>const string &amp; wrap2(const string &amp; s1, const string &amp; s2){
    return (s2 + s1 + s2);  
}
</code></pre>
