I have defined a Player class to do some operations with, so it is convenient for me to overload some basic operators. Specifically, I want to use < for comparisons between Player objects. As such, I have the following in the class:
bool operator<(const Player& rhs) const {return (*this < rhs );}
Unfortunately, this has led to problems. Later, when I try to output a vector containing particular elements in my main function, the compiler lets me know that there is no match for the << operand, and it expects std::ostream << Player. Below is the line causing the issue:
vector<Player> playerVec(6);
for (int i = 0; i < 6; i++) {
cout << playerVec[i];
}
Note that I do not actually want to output any Player objects directly to stream, so I don't think I need to overload <<.
I have some idea of what is going on, in that the compiler takes my specific definition for < and then doesn't bother looking for the more general case. My question is, do I need to now overload the << operator to return its general functionality, or is there a simpler solution?
Thanks for any help provided!