const string declaration

im working on a poker game and im trying to declare and initialize strings to represent card faces/suits

and im getting some very strange erros such as... fatal error cannot recover from previous error(s) stopping compilation

anyways this is the code please let me know what im doing wrong

i've already deleted my debug folder in order to re compile it and im still getting this error when i uncomment it out

1
2
3

const string FACE[13] = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"};
	const string SUIT [4] = {"S","C","D","H"};


i've actually got the previous error to go away it just gives me syntax errors for the [] braces
1
2
const string FACE[13] = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"};
//                      ^ 
Last edited on
Error 2 error C2238: unexpected token(s) preceding ';' c:\users\x d y n a s 7 y\desktop\afternoon\poker heroz\poker heroz\deck.h 10

thats one of the errors thats now coming up i've got like 8 of them :S

and the previous code was wrong this is it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

#include "Card.h"


class Deck : Card
{

	//const string SUIT[4];
	//const string FACE[13];
	const string FACE[13] = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"];
	const string SUIT [4] = ["S","C","D","H"];

	int MAX_CARDS[52];

public:
		
	Deck();
	void Shuffle();
	void show_cards();
	int get_card(int cardID);
};
const string FACE[13] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
i tried that ... and i still get 12 errors

Error 2 error C2334: unexpected token(s) preceding '{'; skipping apparent function body c:\users\x d y n a s 7 y\desktop\afternoon\poker heroz\poker heroz\deck.h 10


Error 1 error C2059: syntax error : '{' c:\users\x d y n a s 7 y\desktop\afternoon\poker heroz\poker heroz\deck.h 10


does it need to be declared b4 its initialized??
im kinda confused... lol
Maybe it's the whitespace between SUIT and [4].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// i took the randomizer from freedosauras.com
#include "Card.h"


class Deck : Card
{

	//const string SUIT[4];
	//const string FACE[13];
	const string FACE[13] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
	const string SUIT[13] = {"S","C","D","H"};


	int MAX_CARDS[52];

public:
		
	Deck();
	void Shuffle();
	void show_cards();
	int get_card(int cardID);
};

Last edited on
i might just post the entire thing maybe the problem is originating somwhere else??
Card.h

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

#ifndef CARD_H
#define CARD_H

#include <iostream>
#include <string>


using namespace std;

class Card
{
public:

	Card();
	Card(int newSuit, int newFace);
	void set_suit(int newSuit);
	void set_face(int newFace);

	

protected:

		int suit;
		int face;
		int cardID;
		int card[52];

	

};

#endif 


Card.cpp

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

#include "Card.h"



Card::Card()
{

}


Card::Card(int newSuit, int newFace)
{
	set_suit(newSuit);
	set_face(newFace);
}

void Card::set_suit(int newSuit)
{
	suit = newSuit;
}

void Card::set_face(int newFace)
{
	face = newFace;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

class Player
{
	int hand[2];

public:

	Player();
	void set_card(int cardID);
	void show_cards();
	int get_card(int cardID);
	int get_face(int cardID);
	int get_suit(int cardID);
};


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
#include "Card.h"
#include "Player.h"
#include "Deck.h"

Player::Player()
{
	for(int i = 0; i < 2; i++)
	{
		hand[i] = -1; // -1 represents no card
	}
}

void Player::set_card(int cardID)
{
	int temp = 0;

	for(int i= 0; i < 2; i++)
	{
		if(hand[i] == -1)
		{
			hand[i] = cardID;
			return;
		}
	}
}

void Player::show_cards()
{
	for(int c = 0; c < 2; c++)
	{
		if(hand[c] != -1)
		{
			cout << hand[c] << " ";
		}
	}
}


int Player::get_face(int cardID)
{
	return cardID & 13;
}


i might just change the const string suit/face to enums because its giving me too many problems and i dont have time to mess with it
string should be std::string
yeah but i put using namespace std; so it should work fine shouldnt it?
Topic archived. No new replies allowed.