I am trying to make an algorithm that plays blackjack perfectly. My first step is to create the deck of cards. I was thinking something like this:
struct cards {
int value;
string suit;
};
int main()
{
cards deck[52] = {}
for (int i = 2; n < 15; n++)
{
I think using a class or struct would be ideal to be able to assign a value and suit to each card by an int and string, respectively. Then I want to make an array of type cards, but I am very confused on how I should initialize it to create the values.
Would greatly appreciate any help--in letting me know if I am headed in the right direction and how to properly initalizing by looping through and setting the values. Thanks!
I am not the original person who posted this message, but I have a question. Please help me.
Why do we use friend std::ostream& operator<< ( std::ostream& stm, card c ).
Why do we use friend ? Couldn't we use it as regular function as below, without using
friend ?
std::ostream& operator<< ( std::ostream& stm, card c )
{
static const char suit_char[] = "SHDC" ;
static const char value_char[] = " 23456789TJQKA" ;
return stm << suit_char[c.suit] << ( c.valid() ? value_char[c.value] : '?' ) ;
}
> Couldn't we use it as regular function as below, without using friend?
Yes, we could.
The only differences are:
a. The non-member friend function defined within the body of the class is implicitly inline.
b. If a declaration of the function at the namespace scope is not provided (as in the above case),
the function can't be found via ordinary name look up (it can only be found via ADL).
This may be useful in large code bases (may reduce compilation times), where there are many other types for which the stream insertion operator has been overloaded.