Haven't worked with classes for a while, so please excuse all these dumb questions :P Still learning. Let me know if you need more info.

1>c:\users\adam\documents\visual studio 2010\projects\help\pusoy\pusoy\pusoy.cpp(24): error C3867: 'Deck::dealCard': function call missing argument list; use '&Deck::dealCard' to create a pointer to member

deck[] is a vector of Card (class)
I have a feeling that this is a bad way to do it anyways.

// Issue out the first card in the deck and then delete it from the deck
Card & Deck::dealCard()
{
	// Create temporary card
	Card temp = deck[0];
	// Delete top of deck
	deck.erase(deck.begin());
	return temp;
}

hand is a vector of Card

void Hand::addCard(Card & d)
{
	hand.push_back(d);
}

Main

int _tmain(int argc, _TCHAR* argv[])
{
	Deck testDeck;
	Card testCard;
	for (int i = 0; i < 52; i++)
		std::cout << testDeck.accessCard(i) << std::endl;
	testDeck.shuffleDeck();
	for (int i = 0; i < 52; i++)
		std::cout << i << ") " << testDeck.accessCard(i) << std::endl;
	Hand testHand[4];
	for (int i = 0; i < 13; i++)
	{
		testHand[0].addCard(testDeck.dealCard); // ERROR HERE
	}
	std::cin.get();
	return 0;
}

Recommended Answers

All 3 Replies

Try this for Main line 13.

testHand[0].addCard(testDeck.dealCard());

Your dealCard member function has a serious flaw: It returns a reference to a local variable, which will refer to nothing valid after the function has returned. You should probably just return a Card (assuming that Card is a class whose values you can copy).

If you're going to use a vector to represent your deck of cards, you should really take cards off the end, not the beginning. The reason is that every time you take a card off the beginning, the library has to copy all the rest of the cards.

Also, I note in passing that before you remove a card from a deck, you should really verify that the deck is not empty.

You can implement these three suggestions by changing the dealCard member as follows:

Card Deck::dealCard()
{
    assert(!deck.empty());
    // Create temporary card
    Card temp = deck.back();
    // Take the card out of the deck
    deck.pop_back();
    return temp;
}

Yeah, thats what i originally had, but the error message said something about an &. So i added one :S Ty fixed it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.