title: Number of arguments in operator overload in C++
body: <p>I'm learning C++ and I created two simple hello-world applications. In both of them I use operator overload, but here is the problem. On the first one, I can provide two arguments to overload operator, and it's fine.</p>
  
  <p><em>Header:</em></p>
  
  <pre><code>enum Element {a,b,c,d,e};
  Element operator + (Element x, Element y);
  //more overloads for -, *, / here
  </code></pre>
  
  <p><em>Source:</em></p>
  
  <pre><code>Element operator + (Element x, Element y) {
      return ArrayOfElements[x][y];
  }
  </code></pre>
  
  <p>But in my second app (simple complex number calculator) - this method didn't work. After googling and figuring out why, I end up with this code:</p>
  
  <p><em>Header:</em></p>
  
  <pre><code>struct Complex {
          double Re;
          double Im;
  
          Complex (double R, double I) : Re(R), Im(I) { }
  
          Complex operator + (Complex &amp;Number);
          //more overloads
      };
  </code></pre>
  
  <p><em>Source:</em></p>
  
  <pre><code>Complex Complex::operator + (Complex &amp;Number)
      {
          Complex tmp = Complex(0, 0);
          tmp.Re = Re + Number.Re;
          tmp.Im = Im + Number.Im;
          return tmp;
      }
  </code></pre>
  
  <p><strong>It's working now, but I want to know, why in the first piece of code I was allowed to put two arguments in <code>operator</code> overloading, but with the second one I was given the following error?</strong></p>
  
  <pre><code>complex.cpp:5:51: error: 'Complex Complex::operator+(Complex, Complex)' must take either zero or one argument
  </code></pre>
  
  <p>It's the same whenever I use classes or not. I've been seeking through many docs and the second way seem to be more correct. Maybe it's because of different argument types?</p>
  
  <p>Both sources compiled with <code>-Wall -pedantic</code> parameters using <code>g++</code>, both are using the same libraries.</p>