Self operator override - Return by reference or return by copy
<p>Consider the following code?</p>

<p>I was wondering, if I change it from (Function body still the same)</p>

<pre><code>error_code&amp; operator|=(const error_code &amp;e)
</code></pre>

<p>to</p>

<pre><code>error_code operator|=(const error_code &amp;e)
</code></pre>

<p>Is there any potential bug that might possible occur? The only difference I see is, it will perform an extra copy operation, other than that, no big deal.</p>

<p>So, should I just stick to return by reference, or it doesn't matter?</p>

<hr>

<pre><code>class error_code {
public:
 error_code() : hi(0), lo(0) {}
 error_code(__int64 lo) : hi(0), lo(lo) {}
 error_code(__int64 hi, __int64 lo) : hi(hi), lo(lo) {}

 // How about return by copy?
 error_code&amp; operator|=(const error_code &amp;e) {
  this-&gt;hi |= e.hi;
  this-&gt;lo |= e.lo;
  return *this;
 }

 __int64 hi;
 __int64 lo;
};

error_code operator|(const error_code&amp; e0, const error_code&amp; e1) {
 return error_code(e0.hi | e1.hi, e0.lo | e1.lo); 
}

int main() {
 error_code e0(1);
 error_code e1(2);
 e0 |= e1;
}
</code></pre>
