Difficulty understanding classes

I am wanting to make a simple blackjack game in c++ using classes. I can do this without classes, but to fully understand the language I would like to use them.
I saw this code in a source on the internet.
Can someone explain how classes work? (Specifically the scope, constructor/destructor).

class Card
{
public:
enum rank {ACE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN,
JACK, QUEEN, KING};
enum suit {CLUBS, DIAMONDS, HEARTS, SPADES};

//overloading << operator so can send Card object to standard output
friend ostream& operator<<(ostream& os, const Card& aCard);

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;
suit m_Suit;
bool m_IsFaceUp;
};

Card::Card(rank r, suit s, bool ifu): m_Rank(r), m_Suit(s), m_IsFaceUp(ifu)
{}
Just look at the chapter that introduces classes in your book.
The constructor is called when the object is created and the destructor is called when the object is deleted. The same scope rules as for int etc. apply for classes.
So same scope, but does that mean that they have to be initialized in int main() to stay throughout the entire program?
If I call a function in main will stay in main's scope or the called function's scope?
Like I said, the same rules apply as if it were an int.
A variable defined in main is not available in other functions, unless you pass it as a parameter to other functions.
If you need variables that exist throughout the entire program, you can also use global variables or static class variables (see "singleton pattern").
Topic archived. No new replies allowed.