Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerations

Status
Not open for further replies.

SotonStu

Programmer
May 7, 2003
33
GB
I have to deal with an enumeration of card suits, decared as follows:
enum suits {spades, clubs, hearts, diamonds};

to create a new card i have to set a private short: value(its value, between 1 and 13) and a private suits: suit.
My program will read in a list of 52 cars in the format:
9 H
1 S
11 C etc.
How do i assign my card a suit using the enumeration, do i say suit = suits{3} or suits{hearts} or what.

thanks for any help
 
Code:
class Card {
   enum suits {spades, clubs, hearts, diamonds};

   suits m_suit;
   int m_rank; // 1..13

public:
   void set_suit(suits suit);
   suits get_suit() const;
   void set_rank(int rank);
   int get_rank() const;
};

////////////////////////

void Card::set_suit(suits suit)
{
   m_suit = suit;
}

////////////////////////

Card card;
card.set_suit(Card::spades);

I REALLY hope that helps.
Will
 
suit = hearts;

[sub]Nerdy signatures are as lame as the inconsistent stardates of STTNG.[/sub]
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top