Declaring an array of a class

Hey. I'm coding a text card game using classes 'card' and 'deck'. Now, in order for 'deck' to compile and function like a real life deck of cards, it needs to declare 52 different cards.
I was wondering how I would do this. Here's my card class.
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//Card.h - A reusable card class
namespace cardgame
{
	class card
	{
	protected:
		enum face
		{
			ace, two, three, four, five, six, seven, eight, nine, ten, Jack, Queen, King, Joker
		} value;

		enum suit
		{
			spade, diamond, club, heart
		}type;

		enum location
		{
			inhand, indeck,
		}loc;

		bool faceup;

	public:
		card(card::face val, card::suit tpe, card::location startloc, bool up = false) //Constructor A: The Full Constructor
		{
			value = val;
			type = tpe;
			loc = startloc;
			faceup = up;
		};

		card(face val, card::suit tpe, bool up = false) //Constructor B: The 'indeck' Constructor
		{
			value = val;
			type = tpe;
			loc = indeck;
			faceup = up;
		};

		bool flip(card)
		{
			if(faceup == true)
			{
				faceup = false;
			}
			else
			{
				faceup = true;
			}
			return faceup;
		};

	};
	
}




Just create it like you would any other array, i.e.:

TYPE[52] NAME;
I think that you should add a constructor with no arguments or with only optional arguments
Additionally, you could default the location in the constructor like you defaulted up. Then you would only have one constructor, so far.

Here's another improvement that could save you some lines: replace lines 43-50 with: faceup = !faceup;
Topic archived. No new replies allowed.