get hands in poker doulbe linked list c++

I have a class Hand, which will hold (if it's finished) 5 cards. Those cards are pointer. I have another class Deck, here I have all my cards. In my class Deck, I have a function print() to print my all my cards, and getLast() which returns a variable of type card (attributes of card are fsuit and fvalue, example D (diamants) 5 (rank of card)

This following function should add the attributes of the last cards of my Deck to a new card, and add that card to a players hand.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Hand::AddCard()
{
	int PokerHandLenght = 5; //amount of cards in hand

	Card * NewCard = new Card(); //new card

	BoekCards * RemoveLast; //BoekCards (class for deck) pointer named RemoveLast
	char suit= RemoveLast->getLast()->fsuit; //a char wich holds the suit of the card that get returned in function getLast()
	suit = NewCard->fsuit; //I assign char suit to the fsuit attribute of my new card

	RemoveLast->removeLast(); //remove the old card from the deck
	RemoveLast->print(); //print the deck again, it should be 51 cards


}
That's pretty cool. Is is there any reason why you chose to use a doubly linked list instead of a templated deque or vector? Did you write said list or are you referring to the STL list?

P.S- Did you have a question or something? I lol'd at the pointer to a pointer on line 8. Good stuff.
Last edited on
I need to use doubly linked list, school project. I don't even know if your LOL works, segmentation fault sucks.
Seg faults are actually good. They tell you that your program is flawed. Try to re-evaluate why you are accessing a pointer to a pointer and see if there is a simpler way to accomplish it. I see a few people on here using pointers in excess that will yield insignificant performance gains and yet add even more challenging programming maintenance.

Also make sure you set your pointers to NULL in every constructor aside form the Copy Constructor. JUst remember that even array can give you seg faults. It just means you are trying to access unallocated memory.
Topic archived. No new replies allowed.