Problems with C ++ with an array of objects

We have a task to create a blackjack game.

Bellow is a 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 creating an array of objects. the compiler gives me the following errors:

Error C3646 'cards': unknown override specifier

Error C2143 with the syntax: missing ',' before '['

Error C2143 syntax error: missing ')' before ';'

Error C2238 unexpected token (s) preceding ';'

What is wrong with my code?

+7
c ++ object arrays
source share
1 answer

The compiler does not know what Map is, therefore, it cannot generate the correct code.

The Card class must be declared before the Deck class because Card included in 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; } 
+8
source share

All Articles