C++ Beginner - Simple block of code crashing, reason unknown.
- by Francisco P.
Hello everyone,
Here's a block of code I'm having trouble with.
string Game::tradeRandomPieces(Player & player)
{
string hand = player.getHand();
string piecesRemoved;
size_t index;
for (size_t numberOfPiecesToTrade = rand() % hand.size() + 1; numberOfPiecesToTrade != 0; --numberOfPiecesToTrade)
{
index = rand() % hand.size();
piecesRemoved += hand[index];
hand.erase(index,1);
}
player.removePiecesFromHand(piecesRemoved);
player.fillHand(_deck);
return piecesRemoved;
}
I believe the code is pretty self explanatory.
fillhand and removepiecesfromhand are working fine, so that's not it.
I really can't get what's wrong with this :(
Thanks for your time