Slagathor
Mechanical
- Jan 6, 2002
- 129
Help!
I am teacing myself C++, and need some guidance. The project I created for myself to teach myself about OOP is a Card game simulation. I just started. Outline is a follows:
Class Card;
Private Data Members:
int Rank //2-14 to represent 2-Ace)
char Suit; //ASCII codes 0x03-0x06 for suit
unsigned long Index //this will be used to shuffle
Public Methods:
Card(); //The default constructor...assigns nulls)
int getRank(void); //returns Suit
char getSuit(void); //returns Rank
unsigned long getIndex; //returns Index
void SetCard(int rank); //Overloaded Function
void SetCard(char suit);
void SetCard(uns long index);
void SwapCards(Card A, Card B); //Swaps two cards data
void DisplayCard(); //Displays Rank, Suit and Index
Class Deck;
Private Data Members:
Deck Card[52];
Public Methods;
Deck(); //Default constructor..assigns Rank and Suits
Display(); //Displays all 52 cards
Shuffle(); //Shuffles Deck
Ive got this all working and implemented excepted for the Shuffle() method.
I have structured the progam as follow
main.cpp
Card.cpp (implementation of Card Methods)
Deck.cpp (implementation of Deck Methods)
Random.cpp (random number generation function implemtation)
QuickCardSort.cpp (Quicksort to work on object array with
an unsigned long index field in the
object)
Card.h
Deck.h
Random.h
QuickCardSort.cpp
I can call the random function, but I am having problem with QuickCardSort. The problem is that I am calling QuickCardSort from withing the Shuffle method for Deck. I do this because I want to protect the data within the deck.
Problem is that "Card.h" must be included in Deck. QuickCardSort must also have "Card.h" included as this function is tailored to the Card Class. (I am not yet far enough along to figure out how to use a Template to make my sorting fuction more generic (able to act on multiple ata types...) Problem is I now have a redifintion of the Card class, and it wont compile?
How do you get around Class Redefinition? Do I have to use a template based Sorting Function? Can I use the "stadafx" header and include "card.h" there?
Any pointers (no pun intended) would be appreciated...
I am teacing myself C++, and need some guidance. The project I created for myself to teach myself about OOP is a Card game simulation. I just started. Outline is a follows:
Class Card;
Private Data Members:
int Rank //2-14 to represent 2-Ace)
char Suit; //ASCII codes 0x03-0x06 for suit
unsigned long Index //this will be used to shuffle
Public Methods:
Card(); //The default constructor...assigns nulls)
int getRank(void); //returns Suit
char getSuit(void); //returns Rank
unsigned long getIndex; //returns Index
void SetCard(int rank); //Overloaded Function
void SetCard(char suit);
void SetCard(uns long index);
void SwapCards(Card A, Card B); //Swaps two cards data
void DisplayCard(); //Displays Rank, Suit and Index
Class Deck;
Private Data Members:
Deck Card[52];
Public Methods;
Deck(); //Default constructor..assigns Rank and Suits
Display(); //Displays all 52 cards
Shuffle(); //Shuffles Deck
Ive got this all working and implemented excepted for the Shuffle() method.
I have structured the progam as follow
main.cpp
Card.cpp (implementation of Card Methods)
Deck.cpp (implementation of Deck Methods)
Random.cpp (random number generation function implemtation)
QuickCardSort.cpp (Quicksort to work on object array with
an unsigned long index field in the
object)
Card.h
Deck.h
Random.h
QuickCardSort.cpp
I can call the random function, but I am having problem with QuickCardSort. The problem is that I am calling QuickCardSort from withing the Shuffle method for Deck. I do this because I want to protect the data within the deck.
Problem is that "Card.h" must be included in Deck. QuickCardSort must also have "Card.h" included as this function is tailored to the Card Class. (I am not yet far enough along to figure out how to use a Template to make my sorting fuction more generic (able to act on multiple ata types...) Problem is I now have a redifintion of the Card class, and it wont compile?
How do you get around Class Redefinition? Do I have to use a template based Sorting Function? Can I use the "stadafx" header and include "card.h" there?
Any pointers (no pun intended) would be appreciated...