C++ -- why the operator= return a reference to *this rather than an object to *this?
<pre><code>class MyClass {
  public:
    ...
    MyClass &amp; operator=(const MyClass &amp;rhs); // return MyClass&amp;
    ...
  }
</code></pre>

<p>why not</p>

<pre><code>class MyClass {
  public:
    ...
    MyClass  operator=(const MyClass &amp;rhs); // return MyClass
    ...
  }
</code></pre>

<p>Is it the reason that it is more efficient to return by reference in this case?</p>

<p>Thank you</p>

<p>// <strong>* updated *</strong></p>

<p>I think I found the key reason as follows:</p>

<pre><code>int i1, it2, i3;
(i1 = i2) = i3; // i3 will be assigned to i1
</code></pre>

<p>If the return type of operator= is MyClass rather than MyClass&amp;, then the following statement doesn't perform the same as the internal data type.</p>

<pre><code>MyClass mc1, mc2, mc3;

(mc1 = mc2) = mc3;
</code></pre>

<p>It is considered as a good practice by following the rules used by the built-in types.</p>

<pre><code>// *** update ***

#include "stdafx.h"
#include &lt;iostream&gt;

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    int i1, i2, i3;

    i1 = 0;
    i2 = 2;
    i3 = 3;

    (i1 = i2) = i3;

    cout &lt;&lt; "i1: " &lt;&lt; i1 &lt;&lt; endl;
    cout &lt;&lt; "i2: " &lt;&lt; i2 &lt;&lt; endl;
    cout &lt;&lt; "i3: " &lt;&lt; i3 &lt;&lt; endl;

    return 0;
}

// output from VS2010
/*
i1: 3
i2: 2
i3: 3
*/
</code></pre>
