I have the following code in my program for a blackjack game:
Player *p;
Deck *d = new Deck();
Hand *playerHand = new Hand(), *dealerHand = new Hand();
p = get_Simple(); //This returns a pointer to an instance of a Simple Player for my game
Card dealerCard = d->deal();
p->draw(dealerCard, playerHand);
draw is defined as
virtual bool draw(Card dealer, const Hand &player);
When I try to run this code, I get the following error:
error: no matching function for call to 'Player::draw(Card&, Hand*&);
note: candidates are: virtual bool Player::draw(Card, const Hand&);
T* x = new T()is, like, never a good idea in C++. Why not justHand playerHand?new T()just sets a few default values for each of the objects, which wouldn't be done if I just calledHand playerHand. I guess I could set them manually, but it seemed easier to just use the pointers. Judging by the answers here, I might've been wrong, haha.Hand playerHand;andHand* playerHand = new playerHand();produce different objects, then you can fix that in your constructor by initializing your POD sub-objects. Otherwise you can doHand playerHand = Hand();