title: C++ why the assignment operator should return a const ref in order to avoid (a=b)=c
body: <p>I am reading a book about C++ and more precisely about the operator overloading.</p>
  
  <p>The example is the following:</p>
  
  <pre><code>const Array &amp;Array::operator=(const Array &amp;right)
  {
  // check self-assignment
  // if not self- assignment do the copying
  return *this; //enables x=y=z
  }
  </code></pre>
  
  <p>The explanation provided by the book about returning const ref instead of ref is to avoid assignments such as (x=y)=z. I don't understand why we should avoid this. I understand that x=y is evaluated first in this example and since it returns a const reference the =z part cannot be executed. But why?</p>