I took a number of classes back in college with Java, VB, and VB.NET, and a few in C++. I was looking through some of my books the other day and decided to brush up on my C++ programming, as I'd like to get back into writing programs.
I went out and bought a book called "Beginning C++ Game Programming" figuring since I like games it might be fun to refresh myself in the syntax in logic in a very basic game programming type format. I'm having a little problem though with working out how to break a given program into multiple files, to help make things more clear. The last program in the book is a very simple version of blackjack. It's 606 lines long with code and all my commenting, with 7 different classes. I want to break each class into it's own file that's included.
The way the suggest to do this is to break the class into two files each with the same name as the class, one a header file (.h) that has the class definition, and one a (.cpp) file with all the member function definitions. My first question is do you have to break things down like this, or could you include both in one file like you can in other languages? Second I am having a problem with an overloaded operator (<<) that they use that's a friend of the Card class. When I try to break it into it's own file, and then include it (#include "card.h") it gives me an error with an undefined ostream. I include the iostream header in the card.cpp file, do I need to include it as well in the card.h file; or is there some other more basic problem I'm missing?
Here's the Card class definition (without the member function definitions):
class Card
{
public:
//Create a list of card values
enum rank {ACE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE,
TEN, JACK, QUEEN, KING};
//Create a list of card suits
enum suit {CLUBS, DIAMONDS, HEARTS, SPADES};
//Overloading << operator so can send Card object to standard output
friend ostream& operator<<(ostream& os, const Card& aCard);
//Constructor
Card(rank r = ACE, suit s = SPADES, bool ifu = true);
//Returns the value of a card, 1 - 11
int GetValue() const;
//Flips a card; if face up, becomes face down and vice versa
void Flip();
private:
rank m_Rank; //Holds the cards rank (value)
suit m_Suit; //Holds the cards suit
bool m_IsFaceUp; //Holds wether the card is face up or not
}; //End of class Card
That is essentially what I have in the card.h file, between the #ifndef, #define, and #endif lines. Any help in this would be greatly appreciated. If I can figure how to work this out I'm going to start planning what kind of program I want to try and make on my own accord - to see how well I've refreshed myself.