title: error: overloaded 'operator<<' must be a binary operator (has 3 parameters)
body: <p>I know there are plenty of questions like these, but I couldn't find a solution that worked for me. </p>
  
  <p>I am trying to make simple fraction calculator than can add or subtract any number of functions and write the answer as a reduced fraction. </p>
  
  <p><em>Example: input=
  3/2 + 4/
  8
  , output =
  2</em></p>
  
  <p>I am trying overload operators in order to accomplish this.</p>
  
  <p>So in the program I am trying to develop, the input consists of an expression made of fractions separated by the operators <code>+</code> or <code>-</code>. </p>
  
  <p>The number of fractions in the expression is arbitrary. </p>
  
  <p>Each of the following 6 lines is an example of a valid input expression:</p>
  
  <pre><code>1/2 + 3/4
  1/2 -5/7+3/5
  355/113
  3    /9-21/    -7
  4/7-5/-8
  -2/-3+7/5
  </code></pre>
  
  <p>***The problem that I am having is that in when I run my program it has an overload operating error: *error: overloaded 'operator&lt;&lt;' must be a binary operator (has 3 parameters)**** </p>
  
  <pre><code>  /Users/Spicycurryman/Desktop/ECS40/hw1/fraction.cpp:61:22: error: overloaded 'operator&lt;&lt;' must be a binary operator (has 3 parameters)
    ostream&amp; Fraction::operator&lt;&lt;(ostream &amp;os, Fraction&amp; n)
                       ^
  /Users/Spicycurryman/Desktop/ECS40/hw1/fraction.cpp:80:22: error: overloaded 'operator&gt;&gt;' must be a binary operator (has 3 parameters)
    istream&amp; Fraction::operator&gt;&gt;(istream &amp;os, Fraction&amp; n)
  </code></pre>
  
  <p>I don't understand why that is an error. </p>
  
  <p>My following code is below:</p>
  
  <p><strong>CPP FILE</strong></p>
  
  <pre><code>#include "Fraction.h"
  
  Fraction::Fraction(int a, int b)
  {
  
  }
  int Fraction::find_gcd (int n1, int n2) 
  {
    int gcd, remainder;
  
    remainder = n1 % n2; 
    while ( remainder != 0 )
    {
      n1 = n2;
      n2 = remainder; 
      remainder = n1 % n2; 
    } 
    gcd = n2; 
  
    return (gcd);
  }
  
  void Fraction::reduce_fraction(int nump,  int denomp) 
  {
    this-&gt;nump = nump;
    this-&gt;denomp = denomp; 
    int gcd;   
    gcd = find_gcd(nump, denomp);
    nump = nump / gcd;
    denomp = denomp / gcd;
  
      if ((denomp&lt;0 &amp;&amp; nump &lt; 0 ))
      {
          denomp*=-1;
          nump*=-1;
      }
      else if (denomp &lt; 0 &amp;&amp;  nump &gt;0){
          denomp*=-1;
  
      }
      if ( denomp ==0) {
          throw invalid_argument( "Error: zero denominator" );
      }   
  }
  
  
  
  Fraction&amp; Fraction::operator+(const Fraction&amp; n) {
      denom = denomp * n.denom;
      numera = (nump * n.numera) + (n.denom * n.nump);
      return (*this);
  
  }
  
  Fraction&amp; Fraction::operator-(const Fraction&amp; n) {
      denom = denomp * n.denom;
      numera = (nump * n.numera) - (n.denom* n.nump);
      return (*this);
  }
  
    ostream&amp; Fraction::operator&lt;&lt;(ostream &amp;os, Fraction&amp; n)
  {
      if (n.numera == 0)
      {
          cout &lt;&lt; 0 &lt;&lt; endl;
          return os;
      }
      else if (n.numera == n.denom)
      {
          cout &lt;&lt; 1 &lt;&lt; endl;
          return os;
      }
      else
      {
          cout &lt;&lt; n.numera &lt;&lt; '/' &lt;&lt; n.denom &lt;&lt; endl;
          return os;
      }
  }
  
    istream&amp; Fraction::operator&gt;&gt;(istream &amp;os, Fraction&amp; n)
  {
      char slash = 0;
      return os &gt;&gt; n.numera &gt;&gt; slash &gt;&gt; n.denom;
  
  }
  </code></pre>
  
  <p><strong>Header File</strong></p>
  
  <pre><code>#ifndef FRACTION_H
  #define FRACTION_H
  #include &lt;iostream&gt;
  #include &lt;stdexcept&gt;
  using namespace std;
  
  
  class Fraction{
  
      public: 
      Fraction(int a, int b);
      int fraction(int a,int b);
      int find_gcd(int n1, int n2); 
      void reduce_fraction(int nump,  int denomp);
      Fraction&amp; operator+(const Fraction&amp; n);
      Fraction&amp; operator-(const Fraction&amp; n);
      friend ostream&amp; operator&lt;&lt;(ostream &amp;os, const  Fraction&amp; n);
      friend istream&amp; operator&gt;&gt;(istream &amp;is, const Fraction&amp; n);
  private:
      int denom;
      int numera;
      int denomp;
      int nump;
  
  
  
  };
  
  #endif
  </code></pre>
  
  <p><strong>MAIN CPP FILE</strong></p>
  
  <pre><code>#include "Fraction.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
    Fraction x(2,3);
    Fraction y(6,-2);
  
    cout &lt;&lt; x &lt;&lt; endl;
    cout &lt;&lt; y &lt;&lt; endl;
  
    cin &gt;&gt; y;
    cout &lt;&lt; y &lt;&lt; endl;
    Fraction z = x + y;
    cout &lt;&lt; x &lt;&lt; " + " &lt;&lt; y &lt;&lt; " = " &lt;&lt; z &lt;&lt; endl;
  }
  </code></pre>
  
  <p>I know that the operators are member functions and a member function takes an implicit first parameter, meaning my operators now takes three parameters it may be fixed being a non-member function; however, that would not work in this program. How exactly in my case would I fix it so the program would work? </p>
  
  <p>Thank you very much!</p>