Search code examples
c++header-filesblackjack

I stole card game c++ header code and it won't compile... duuhhh


I am a newbie c++ (but fair experience visual basic, visual foxpro) and I'm trying to get to write a blackjack console program. I borrowed (stole, used, etc.) header file snippet from an old thread (Generating a Deck of Cards).

This is the code:

class Card
 {
 public:
 enum ESuit
{
    Hearts,
    Clubs,
    Diamonds,
    Spades,
    Suit_Count
};

enum ERank
{
    Ace,
    Two,
    Three,
    Four,
    Five,
    Six,
    Seven,
    Eight,
    Nine,
    Ten,
    Jack,
    Queen,
    King,
    Rank_Count
};

static int const skNumCards = Suit_Count * Rank_Count;

Card( int cardIndex )
: mSuit( static_cast<ESuit>( cardIndex / Rank_Count ) )
, mRank( static_cast<ERank>( cardIndex % Rank_Count ) )
{}

ESuit GetSuit() const { return mSuit }; // should be mSuit; }
ERank GetRank() const { return mRank }; // should be mRank; }

private:
    ESuit mSuit;
    ERank mRank;
}  // missing ending ;  should be }; 

It does not compile correctly. Something is wrong with the lines:

ESuit GetSuit() const { return mSuit };  // should be mSuit; }
ERank GetRank() const { return mRank };  // should be mRank; }

private:
    ESuit mSuit;
    ERank mRank;   

Thank you in advance for any help.


Solution

  • Those lines should be

    ESuit GetSuit() const { return mSuit; }
    ERank GetRank() const { return mRank;}
    

    You also need a semi-colon after the closing brace of your class definition.