Is Returning by Reference Useless?
<p>Coming from a C# background, I was more or less puzzled by the seemly weird behavior of returning method handling in C++. My concern now is for a method in C++, returning by reference is not a very useful technique, this is because-- unlike C#--any variable declared inside a method body will go out of scope once the the control exit the method.</p>

<p>So, in C++, <a href="http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/" rel="nofollow">this</a> cannot even compile ( but an equivalent version in C# <em>can</em>):</p>

<pre><code>int&amp; DoubleValue(int nX)
{
    int nValue = nX * 2;
    return nValue; // return a reference to nValue here
} // nValue goes out of scope here
</code></pre>

<p>The only time where returning by reference is useful is when you are returning a reference to an existing data member in a class, or you are returning a reference to an element inside a parameter of the method. But in both cases there is really no need to return anything; as the  returned reference is already freely available to the caller of the method.</p>

<p>So, my conclusion is, there is no need to use return by reference at all. Am I right?</p>
