I am writing a game in which there are 2 players, "BLACK" and "WHITE".
I have the following enum class:
enum class PlayerType
{
BLACK, WHITE
};
I would like to write an ostream operator<< for this class. Here is my attempt:
std::ostream& operator<<(std::ostream& os, const PlayerType& pt)
{
if(pt == PlayerType::BLACK)
os << "Black";
return os;
}
However I get the following compiler error:
operator<< must take exactly 1 argument
I think the problem is that I am nesting the enum class, and operator<< inside another class; class Player
.
Is there anything I can do about this without removing the enum from within this class?