0

I'm trying to create a Blackjack simulator. I need to shuffle the deck before dealing cards to both the player and the dealer. shuffleDeck is a void function and dealCard is of type Card within class Deck. Class Card stores the cards that are dealt from the class Deck. At the very beginning of the game, I need to deal two cards to both the player and the dealer. When I tried to access the member function of Deck in class Game, I got the error message "Call to non-static member function without an object argument". What is the correct way for calling member functions? I'm really confused by the syntax.

void Game::deal()
{
    // shuffle deck
    // deal two cards to the player and two to the dealer
    Deck::shuffleDeck();
    Player::acceptCard (Deck::dealCard());
}
553535782
  • 23
  • 4
  • 4
    First of all you need instances of `Deck` and `Player`, I'd suspect best as member variables of `Game`. – πάντα ῥεῖ Mar 08 '16 at 10:47
  • 1
    You're confusing classes with objects. We usually recommend [this](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) as a starting point. – molbdnilo Mar 08 '16 at 10:50

1 Answers1

0

You are accessing the the class Deck not an instance of Deck! (I suppose your Deck class isn't desinged as a singelton. It should not be a singelton!).

I guess you want to have a member of type Deck in your class Game:

class Game:
{
...
private:
 Deck my_deck;
}

which you can use in your deal method

void Game::deal()
{
    ...
    myDeck.shuffleDeck();
    ...
}
MagunRa
  • 543
  • 4
  • 13