Thanks for the response.
now a Deck has two vectors. |
Yar, I figured this was the problem. The Deck object has it's own vector of cards, as well as a "hidden" vector created when Deck invokes Hand constructor. I imagine this is why a call to my_deck.PrintCards() compiles and executes, but doesn't show the desired results.
> create a Hand class, as well as a Deck class that derives from Hand
I don't like that design. |
I don't have a grasp on smart class design so I'm following the hierarchy outlined in the exercise itself. My hope is that even if it's imperfect, it'll serve as a launching point to learn what goes in to good and bad designs. It's already been helpful, even when struggling with roadblocks. Exercise PDF if interested:
http://www.montefiore.ulg.ac.be/~hoyoux/info0004/info0004-project1-2010.pdf
Given the constraints, what might be reasonable ways for classes that derive from Hand to contain a vector of cards?
My thoughts are:
1) Exercise proposes creating a Deck, Player and House class that derives from Hand.
2) Each Deck, Player and House should have it's own vector of cards since they logically contain cards.
3) Some functions are common to each subclass. Example: Add(Card* card).
Deck will use Add() when populating the playing cards. Player and House will use Add() when cards are dealt out and hit for an additional card.
I'm lost how to implement a function like Add() or PrintCards() in the base class, while avoiding the situation where each derived class has multiple containers. Is the solution to write an Add() function for each derived class? Wouldn't that lead to code duplication?
Thanks again. If anybody has recommendations or links to learn class design then I'd be happy to explore them. I have some (weak) understanding of the C++ mechanics, but not the "smart" ways to design them.