title: C++ overload + operator friend function
body: <p>I am trying to create an overloaded friend function that will add two fractions. So far I have the following solution but I have errors at line 17 and 19. I believe the problem is with the parameters (fraction amount1, fraction amount2) but I can't exactly put my finger on it. Can anyone help? This needs to compile on Visual Studio 2010. </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class fraction
  {
  public:
  fraction(); //constructor for initialize
  void read(); //read 3 int from keyboard for the fraction
  void print(); //print the fraction on screen
  friend fraction operator +(fraction, fraction); //fraction add
  private:
  int integral, numerator, denominator;
  }
  
  
  int main(){
  
  return 0;
  }
  
  fraction operator +(fraction amount1, fraction amount2)
  {
  fraction temp;
  temp.integral = amount1.integral + amount2.integral;
  temp.numerator = amount1.numerator + amount2.numerator;
  temp.denominator = amount1.denominator + amount2.denominator;
  return temp;
  }
  
  
  void fraction::read()
  {
  cin &gt;&gt; integral &gt;&gt; numerator &gt;&gt; denominator;
  }
  </code></pre>
  
  <p>EDIT: I have corrected my addition algorithm to </p>
  
  <pre><code>friend fraction operator +(const fraction&amp;, const fraction&amp;); //fraction add
  </code></pre>
  
  <p>and</p>
  
  <pre><code>fraction operator +(const fraction&amp; amount1, const fraction&amp; amount2)
  {
  fraction temp;
  temp.integral = amount1.integral + amount2.integral;
  temp.numerator = (amount1.numerator)*(amount2.denominator) + (amount2.numerator)*(amount1.denominator);
  temp.denominator = (amount1.denominator)*(amount2.denominator);
  return temp;
  }
  </code></pre>
  
  <p>However on testing this I output zeros for the numerator and denominator variables. Can anyone help with this?</p>