I encode a program where I want to draw a map, and then delete it so that it does not draw again.
I have a Card vector (a class containing 2 structures that define Suit and Value) called a deck, and I really don't know how to use iterators very well, here is 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 that I am about to delete. It is randomly generated within the boundaries of 0 and the size of the deck; therefore, it should not indicate a position outside the borders.
Every time I compile, I get the following error:
"Expression: vector erase iterator outside range"
I really donβt know what to do, I hope someone can help me, thanks in advance!
, getDeck . , itr erase . , . . getDeck :
getDeck
itr
erase
vector<Card>& getDeck()
. . CardDeck - , , , , , . Player CardDeck. , (-), . . , , .
masterDeck.Discard(selectedCard);
, selectedCard 0 ONE LESS, , , , ( 1/53rd )
, , masterDeck. ? , , , , , , . . , , , , . . ++ 11.
, , , . ( , , ). , . , , iter!= Coll.end().
" 0 ".
" 0 1". .