Click here to Skip to main content
16,015,809 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: STRPTIME function in Win Mobile 5.0 Pin
Rajesh R Subramanian22-May-08 20:27
professionalRajesh R Subramanian22-May-08 20:27 
AnswerRe: STRPTIME function in Win Mobile 5.0 Pin
Arun John22-May-08 21:16
Arun John22-May-08 21:16 
GeneralRe: STRPTIME function in Win Mobile 5.0 Pin
Rajesh R Subramanian22-May-08 21:28
professionalRajesh R Subramanian22-May-08 21:28 
QuestionSet Color of other application Pin
Deepak_Agrawal22-May-08 15:00
Deepak_Agrawal22-May-08 15:00 
AnswerRe: Set Color of other application Pin
Hamid_RT22-May-08 18:48
Hamid_RT22-May-08 18:48 
GeneralRe: Set Color of other application Pin
jacks070222-May-08 19:07
jacks070222-May-08 19:07 
GeneralRe: Set Color of other application Pin
Hamid_RT22-May-08 19:16
Hamid_RT22-May-08 19:16 
QuestionUndeclared Identifier Pin
faceninja22-May-08 13:25
faceninja22-May-08 13:25 
Hi,

I have recently started learning C++, having come from a mainly Java/PHP background. I am implementing a Poker library, which is something I do in each new language I learn, as porting the code seems a good way to learn syntax of languages. I have a class for data about single cards in the library:

Card.h

class Card
{
        ..snip..

	const static int CLUBS = 0;
	const static int DIAMONDS = 1;
	const static int HEARTS = 2;
	const static int SPADES = 3;

        ..snip..

public:

	..snip..

	string toString();
	int charsToIndex(char rank, char suit);
};


Card.cpp

string Card::toString()
{
	string s("");
	s += getRankChar(getRank());
	switch (getSuit())
	{
	case HEARTS: s+='h'; break;
	case DIAMONDS: s+='d'; break;
	case CLUBS: s+='c'; break;
	case SPADES: s+='s'; break;
	}

	return s;
}



This code compiles and works fine, and passes all the unit tests I have implemented. However when I try to do the "reverse" of this action, I get a number of compiler errors:

Card.cpp

int charsToIndex(char rank, char suit)
{
      int r = -1;
      switch (rank) {
         case '2': r = TWO; break;
         case '3': r = THREE; break;
         ..snip..
      }
      int s = -1;
      switch (suit) {
         case 'h': s = HEARTS; break;
         case 'd': s = DIAMONDS; break;
         ..snip..
      }
}


The errors are "card.cpp(155) : error C2065: 'TWO' : undeclared identifier", repeated for each time I have used a constant within the charsToIndex function. I can't work out whether I have missed something stupid, or there's something about scope in C++ I don't quite understand.

Thanks in advance for any assistance.
AnswerRe: Undeclared Identifier Pin
Dan22-May-08 14:53
Dan22-May-08 14:53 
AnswerRe: Undeclared Identifier Pin
tataxin22-May-08 15:13
tataxin22-May-08 15:13 
AnswerRe: Undeclared Identifier Pin
Nemanja Trifunovic22-May-08 16:52
Nemanja Trifunovic22-May-08 16:52 
AnswerRe: Undeclared Identifier Pin
Stephen Hewitt22-May-08 18:41
Stephen Hewitt22-May-08 18:41 
AnswerRe: Undeclared Identifier Pin
faceninja23-May-08 7:11
faceninja23-May-08 7:11 
Questionwhats wrong with this code Pin
lahom22-May-08 13:02
lahom22-May-08 13:02 
AnswerRe: whats wrong with this code Pin
Rajkumar R22-May-08 20:26
Rajkumar R22-May-08 20:26 
GeneralRe: whats wrong with this code Pin
lahom22-May-08 20:50
lahom22-May-08 20:50 
GeneralRe: whats wrong with this code Pin
Rajkumar R22-May-08 20:58
Rajkumar R22-May-08 20:58 
GeneralRe: whats wrong with this code Pin
lahom22-May-08 21:10
lahom22-May-08 21:10 
GeneralRe: whats wrong with this code Pin
Rajkumar R22-May-08 21:35
Rajkumar R22-May-08 21:35 
GeneralRe: whats wrong with this code Pin
lahom22-May-08 21:47
lahom22-May-08 21:47 
GeneralRe: whats wrong with this code Pin
Rajkumar R23-May-08 0:42
Rajkumar R23-May-08 0:42 
GeneralRe: whats wrong with this code Pin
lahom23-May-08 6:59
lahom23-May-08 6:59 
GeneralRe: whats wrong with this code Pin
Rajkumar R24-May-08 3:23
Rajkumar R24-May-08 3:23 
QuestionFile Serialization versus old style data saving on files Pin
Kwanalouie22-May-08 5:56
Kwanalouie22-May-08 5:56 
AnswerRe: File Serialization versus old style data saving on files Pin
CPallini22-May-08 6:02
mveCPallini22-May-08 6:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.