Need feedback on two member functions of a Table class in C++
- by George
int Table::addPlayer(Player player, int position)
{
deque<Player>::iterator it = playerList.begin()+position;
deque<Player>::iterator itStart = playerList.begin()+postion;
while(*it != "(empty seat)") {
it++;
if (it == playerList.end()) {
it = playerList.begin();
}
if (it == itStart) {
cout << "Table full" << endl;
return -1;
}
}
//TODO overload Player assignment, << operator
*it = player;
cout << "Player " << player << " sits at position " << it - playerList.begin() << endl;
return it - playerList.begin();
}
}
int Table::removePlayer(Player player)
{
deque<Player>::iterator it = playerList.begin();
//TODO Do I need to overload != in Player?
while(*it != player) {
it++;
if (it == playerList.end()) {
cout << "Player " << player << " not found" << endl;
return -1;
}
}
*it = "(empty seat)";
cout << "Player " << player << " stands up from position " << it - playerList.begin() << endl;
return it - playerList.begin();
}
Would like some feedback on these two member functions of a Table class for Texas Hold Em Poker simulation. Any information syntax, efficiency or even common practices would be much appreciated.