title: Addition operator overloading for complex numbers
body: <p>I have written the following code to do operator overloading for basic operations on complex numbers, here I have put only the addition. When running it, I get trillions of errors. I have seen several other posts regarding this but I have just started learning C++. I would be most grateful if you could point out in general the mistakes I am making in operator overloading (It is not about debugging, but I would appreciate some general explanations as I have seen examples of the same operator overloading but could not understand several features such as the use of pointer and const). Thanks in advance.      </p>
  
  <pre><code>#include&lt;iostream&gt;
  
  using namespace std;
  
  class Complex 
  {
  private: 
      double real;
      double imaginary;
  
  public:
      Complex(double r, double i);    
      // addition
      Complex operator+(Complex c1, Complex c2);      
  };
  
  Complex::Complex(double r, double i)
  {
      real = r;
      imaginary = i;
  }
  
  Complex Complex::operator+(Complex c1, Complex c2) 
  {
      Complex result;
      result.r = c1.r + c2.r;
      result.i = c1.i + c2.i;
      return result;
  }
  
  ostream ostream::operator&lt;&lt;(ostream out, Complex number)
  {
      out &lt;&lt; number.r &lt;&lt; "+" &lt;&lt; number.i &lt;&lt; endl;
  }
  
  int main() {
      Complex y, z;
      Complex sum;
      y = Complex(2, 4);
      z = Complex(3, 0);
  
      cout &lt;&lt; "y is: " &lt;&lt; y &lt;&lt; endl;
      cout &lt;&lt; "z is: " &lt;&lt; z &lt;&lt; endl;
  
      sum = y+z;
  
      cout &lt;&lt; "The sum (y+z) is: " &lt;&lt; sum &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>