I'm coding a program where I want to draw a card, and then delete so that it doesn't get drawn again.
I have a vector of Cards (class containing 2 structs that define Suit and Value) called deck and I don't really know how to use iterators very well, here a code snippet:
void Player::discardCard(CardDeck masterDeck) { cout << "Erasing: " << masterDeck.getDeck().at(cardSelect).toString() << endl; /*Attempt1*/ masterDeck.getDeck().erase(masterDeck.getDeck().begin()+cardSelect); /*Attempt 2*/ vector<Card>::iterator itr; itr = masterDeck.getDeck().begin() + cardSelect; masterDeck.getDeck().erase(itr); } cardSelect has the location of the card I'm going to delete. It's generated randomly within the boundaries of 0 and the size of deck; therefore it shouldn't be pointing to a position out of boundaries.
Everytime I compile I get the following error:
"Expression: vector erase iterator outside range" I really don't know what to do, hopefully someonw can help me, thanks in advance!
masterDeckby value, maybe that's part of the problem. Otherwise, it might be an extra problem.CardDeck? Also, are you sure you should be passing that by value?std::random_shufflethe vector and then just go through them in order.