Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 30th, 2006, 12:21 AM   #1
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
Which is preferable?

I'm writing a program that uses playing cards. In my card class, I'm not hardcoding the fact that there are four suits and thirteen numbers in each, because I want it to be flexible to allow me to in the future create decks of non-standard cards, e.g. tarot cards.

So I have this:
//suits: number of suits
//numbers: number of members of each suit
template<unsigned suits, unsigned numbers> class Card
{
     /* ... */
}
So far so good. But now I have another class called Deck, which is basically a glorified container for Card. I have two thoughts on how to do this. Either
template<class card_type> class Deck
{
     std::deque<card_type> card_container;
     /* ... */
}
or
template<unsigned suits, unsigned numbers> class Deck
{
     std::deque<Card<suits,numbers>> card_container;
     /* ... */
}
Is there a standard as to which of these is better? If not, are there any advantages or disadvantages to either approach? If not, then it is just a matter of style; which do you prefer?

Note: There may be syntax errors in this post as I'm just getting back into programming after a long absense. I hope, however, that you can understand my point. If you find any errors, please correct me.
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
uman is offline   Reply With Quote
Old May 30th, 2006, 5:14 AM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
The answer is, simply, "it depends".

The first form allows you to create a deck of any type of card (as long as the type acts in a way that your Deck expects) while the second form only supports a deck of your Card<> type.

If all of your cards are going to be a specialisation of your Card class, use the second form. If you anticipate a potential need to use other types of card, use the first form.
grumpy is offline   Reply With Quote
Old May 30th, 2006, 12:11 PM   #3
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
Thanks for the input.
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
uman is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:48 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC