Removing user-defined elements in the middle of a vector

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!

+5
3

, getDeck . , itr erase . , . . getDeck :

vector<Card>& getDeck()
+1

. . CardDeck - , , , , , . Player CardDeck. , (-), . . , , .

masterDeck.Discard(selectedCard);

, selectedCard 0 ONE LESS, , , , ( 1/53rd )

, , masterDeck. ? , , , , , , . . , , , , . . ++ 11.

, , , . ( , , ). , . , , iter!= Coll.end().

+1

" 0 ".

" 0 1". .

0

All Articles