I am trying to define a card class for a card game and am having trouble connecting the values provided to the constructor to some predefined enum types.
Let consider for example enumeration enum Suit {Spades, Diamonds, Clubs, Hearts};
In fact though Spades, Diamonds, Clubs, Hearts have type Suit in C++ they can be implicitly converted to an integral type and their values correspond to 0, 1, 2, 3.
Now consider definition string Card::SuitName = "SDCH";
'S' shall correspond to 0, 'D' - 1, 'C' - 2, and 'H' - 3. How to get these values? If for example the user will enter some character you should check whether this character is valid. You can use string member function find. For example
1 2 3 4 5 6
char c = 'D'; // let assume that this character is a user input.
if ( ( std::string::size_type n = SuitName.find( c ) ) != std::string::npos )
{
Suit s = static_cast<Suit>( n );
}