title: C++ classes: create copy of "this" class within member function
body: <p>I'm trying to write a function for the <code>+=</code> operator of a C++ class which utilizes the already written <code>+</code> operator function. So far, I have been unsuccessful in associating the <code>this</code> pointer with the <code>+</code> operator. These are some of the attempts I've made that compiled in <code>g++</code> but did not produce the desired result. Twice I attempted simply to make a copy of the <code>this</code> class, but that did not appear to work.</p>
  
  <pre class="lang-c++ prettyprint-override"><code>intstr&amp; intstr::operator+=(const intstr&amp; i)
  {
    intstr *a;
    a = new intstr;
    *a = *this + i;
    return *a;
  }
  </code></pre>
  
  <pre class="lang-c++ prettyprint-override"><code>intstr&amp; intstr::operator+=(const intstr&amp; i)
  {
    intstr *a, b(*this);
    a = new intstr;
    *a = b + i;
    return *a;
  }
  </code></pre>
  
  <pre class="lang-c++ prettyprint-override"><code>intstr&amp; intstr::operator+=(const intstr&amp; i)
  {
    intstr *a, *b;
    a = new intstr;
    b = this;
    *a = *b + i;
    return *a;
  }
  </code></pre>
  
  <pre class="lang-c++ prettyprint-override"><code>intstr&amp; intstr::operator+=(const intstr&amp; i)
  {
    intstr *a;
    a = new intstr;
    *a = this-&gt;operator+(i);
    return *a;
  }
  </code></pre>
  
  <p>In the test code, all I've done is replace the working line of code <code>a = a + i</code> with <code>a += i</code>, so I doubt the problem lies there, but it is possible. Is the only way to do this to copy the code from the <code>+</code> operator into the <code>+=</code> function?</p>