title: (c++) How can I use a method of class continuously in the main function?
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  class Complex{
  private:
      double real_;
      double imag_;
  public:
      void set(double m, double n){
          this-&gt;real_ = m;
          this-&gt;imag_ = n;
      }
      void addTo(Complex add){
          this-&gt;real_ += add.real_;
          this-&gt;imag_ += add.imag_;
      }
  };
  int main(){
      Complex a, b, c;
      a.set(1.1, 2.2);
      b.set(1.1, 2.2);
      c.set(1.1, 2.2);
      a.addTo(a).addTo(b).addTo(c);   // problem.
  
      return 0;
  }
  </code></pre>
  <p>I have to use that expression (<code>a.addTo(a).addTo(b).addTo(c);</code>).</p>
  <p>How can I use a method of class continuously in the main function?</p>
  <p>When compiling, it says that the class type should come in front of <code>.addTo(b)</code>, and if I change from <code>void addTo</code> to <code>Complex addTo</code>, I need to set the return value, then, how  can I return <code>a</code>, which called <code>addTo</code>?</p>