Composition in Classes

Hello. I have a card and deck classes going and I am having some trouble.
My deck class encapsulates all of my card objects and when a deck object is created it should initialize the 2D array of cards. The card suit is represented by an enum type and the value is an int.
I am trying to use the setSuit() and getValue() functions from my card class in the deck constructor to initialize the deckArray but I get "setSuit and getValue identifier not found" errors. I don't know how to do this in my deck constructor and I could use some help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;

class card
{
public:
	card(); // default constructor
	void setSuit( cardSuit suitin );
	cardSuit getSuit();
	void setValue( int valuein ); 
	int getValue();
	void toCstring( char cardString[] ); 
private:
	cardSuit suit; // card suit (CLUB, HEART, DIAMOND or SPADE)
	int value; // card value (1 to 13)
};

#include <iostream>
#include "Card.h"
using namespace std;

class deck
{
public:
	deck(); // constructor, every card object in the deck must be initalized with the correct value and suits
	void setCard( card CardIn, int row, int col ); 
	card getCard( int row, int col ); 
	void shuffle();
private:
	card deckArray[ SUITS ][ VALUES ]; // 2D array of card. Each element of the 2D array is a card class object
};

#include <iostream>
#include "Deck.h"
#include "Card.h"

deck::deck( int s, int v): deckArray()
{
        deckArray[ setSuit( s ) ][ getValue( v ) ] 
}


Thanks
deck does not have a constructor with two int arguments declared.
deckArray is an array. it does not have a constructor to call. even if it did, you wouldn't have to call it since default constructors are called implicitly.
setSuit and getValue are methods of card, not deck.
setSuit doesn't return anything so you can't use it to access an element of an array.
even if setSuit and getValue were valid int functions of deck, line 39 would still do nothing. it just returns an element of the array. also there is no ;

I think you wanted
1
2
3
4
5
6
7
deck::deck(){
   for(int s = 0; s < SUITS; s++)
   for(int v = 0; v < VALUES; v++){
      deckArray[s][v].setSuit(s);
      deckArray[s][v].setValue(v);
   }
}
I assume SUITS and VALUES have been defined somewhere..
Topic archived. No new replies allowed.