title: Compund assignment overload (C++)
body: <p>I encountered a problem when passing the same object twice by-reference to a function, once as a constant and once as usual (mutable).</p>
  
  <p>I'd like to know what is the best way to fix such code.
  (a Convenient example is, overloading compound-assignment operators).</p>
  
  <pre><code>class MyClass
  {
      int a, b;
  public:
      MyClass(int a, int b) : a(a), b(b) {}
      MyClass&amp; operator+=(const MyClass&amp; ob)
      {
          this-&gt;a += ob.b;
          this-&gt;b += ob.a;    
          return *this;
      }
  };
  </code></pre>
  
  <p>Of course, this code does not make a lot of sense, but it highlights the problem: 
  When writing the following code:</p>
  
  <pre><code>MyClass ob(1, 2);
  ob += ob;
  </code></pre>
  
  <p>I'd expect ob.b to have the value of 3, but it will have the value of 5.</p>
  
  <p>I wonder how to implement such code correctly in general. 
  Should I just be careful with the implementation, e.g maintaining temporary variables, or is there any better <strong>general</strong> solution for such problems? (E.g pass by value)</p>