We have an assignment to create a game of blackjack.
Bellow is simplified version of my code:
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
class Deck
{
private:
Card cards[52]; <-- HERE!!
public:
};
class Card
{
private:
int suit;
int number;
public:
int getSuit();
int getNumber();
void setCard(int suit, int number);
};
int Card::getSuit()
{
return suit;
}
int Card::getNumber()
{
return number;
}
void Card::setCard(int s, int n)
{
suit = s;
number = n;
}
class Players
{
private:
Card PlayersCards[10];
public:
/*Card getCard();*/
};
//Card Players::getCard()
//{
// return;
//}
int main()
{
Players user;
cin.get();
cin.get();
return 0;
}
The problem is where the array of objects Card is being created. the compiler gives me the following errors:
Error C3646 'cards': unknown override specifier
Error C2143 syntax error: missing ',' before '['
Error C2143 syntax error: missing ')' before ';'
Error C2238 unexpected token(s) preceding ';'
What is wrong with my code?
The compiler doesn't know what Card is, so cannot generate the right code.
The class Card
needs to be declared before the class Deck
, as Card
is included in the Deck
.
class Card {
/// stuff - allows compiler to work out the size of one Card.
};
class Deck {
private:
Card cards[52]; // knows how to create 52 of these.
};
// implementation can go later.
int Card::getSuit()
{
return suit;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With