C++ return local object
<p>Several co-workers and I are having a debate about what happens when a local variable (allocated on the stack) is returned from a C++ method. </p>

<p>The following code works in a unit test, but I believe that is only because the unit test is lucky and doesn't attempt to reuse the memory on the stack used by obj. </p>

<p><strong>Does this work?</strong></p>

<pre><code>static MyObject createMyObject() {
    MyObject obj;
    return obj;
}
</code></pre>
