Q:

Using pop_back() within a public method, but once I exit that method the vector returns to the original

I'm writing a blackjack program. I'm using two different classes, Deck and Game. I have my shuffled deck stored in a vector that is private to the Deck class. I call a Deck method called dealCard() which assigns the last element in the vector to a player, and then pops that element from the vector. This method is called within a Game method, playRound, that deals 2 cards to each player in order. This works fine, and I get 2 different cards for each dealer. However, once the playRound method exits, the vector returns to the original, full deck. 
Card* Decks::dealCard(){
    Card* card = deckList[deckList.size()-1];
    deckList.pop_back();
    return card;
}

void Game::dealRound(int playernum, Decks deck){
    for (int h = 0; h<playernum; h++){
        Card* temp = deck.dealCard();
        players[h]->first = temp;
        cout<<endl;
        deck.printDecks();
    }
    for (int h = 0; h<playernum; h++){
        Card* temp = deck.dealCard();
        players[h]->first->next = temp;
        cout<<endl;
        deck.printDecks();
    }
}

When I use the printDecks() method within the dealRound method, I get the correct deck, which has cards subtracted from the end of the vector. However, once that method exits, if I call printDecks(), it prints out the full deck. Anyone know why this is happening?

A:

Your problem is that dealRound() takes a copy of the deck, meaning it only exists until the end of that function. Instead, try taking either a pointer or reference to the deck.

A:

You are passing a copy of the deck to Game::dealRound, so any alterations do not affect the original deck. Change Games::dealRound to accept the deck by reference:
void Game::dealRound(int playernum, Decks& deck)

