Correct format for overloaded functions in classes

I'm not exactly sure what the correct format for writing an overloaded function for a class is supposed to look like. I was hoping someone could help me out real quick. I have to use overloaded friend functions and non-friend overloaded functions for my class.

Here are example statements in my header file (Fraction is the name of the class)
1
2
3
  friend ostream& operator<<(ostream& output, const Fraction& fract);
  
  Fraction operator+(const Fraction &f1);


here is how I'm defining them in my implementation file
1
2
3
4
5
6
7
8
9
  ostream& Fraction::operator<<(ostream& output, const Fraction& fract);
{
	//code
}

  Fraction Fraction::operator+(const Fraction &f1); 
{
	//code
}

I know this is wrong, but I can't seem to figure out how to make it work.

Last edited on
operator<< is not a member function, so don't put Fraction:: in front of it.

And you need to remove the semicolons at the end of the function head in the implementations.
Thanks a lot. I can't believe I had semi-colons there lol.
Topic archived. No new replies allowed.