Using Classes - Error Problems

I am overloading another operator and am getting an error message that I understand, it's message is clear, but I am not sure how to remedy the issue.

Here is the error:

In function `std::ostream& operator<<(std::ostream&, const Results&)':
175: error: redefinition of `std::ostream& operator<<(std::ostream&, const Results&)'
167: error: `std::ostream& operator<<(std::ostream&, const Results&)' previously defined here

Code in header file for both operators I am overloading. These are not members of the class:
ostream &operator<< (ostream &out, const Results &WR);
ostream &operator<< (ostream &out, const Results &WL);

Code in .cpp file:

/*175*/	ostream &operator<< (ostream &out, const Results &WL) {
   		out << setw(15) << "WORDS: " << setw(15) << "COUNT: " << endl;


I tried using other names within the .cpp file and it has a fit saying that I can't use it because it's type isn't declared - or something to that effect.

Any suggestions would be much appreciated.

Last edited on
You are saying that the error measage is clear then why did you define the operator twice?!
Last edited on
Our instructor told us to do it this way - he gave us the code for both operators.
I see your point though - in other words - I can get it to work if I just get rid of the last operator function. I just wondered if there is some way to use both; that I am somehow not understanding/figuring it out?
Last edited on
To overload something, you need to have different combinations of parameter types. This is so the compiler can tell which one to use.

I am not sure whether you knew that already.
I finally understood what both of you were saying - it was simply a matter of giving the second one a different name.
ostream &operator<< (ostream &out, const WordList &WL);
Topic archived. No new replies allowed.