954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

typedef enum

what's wrong with this line when I try to compile in C++?? The src code was originally in C. It gets an expected identifier error with my c++ compiler

typedef enum {false, true} bool;
number87
Junior Poster in Training
83 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

bool, true, false are already keyword in C++. you don't need to define enum for it.

Laiq Ahmed
Junior Poster
148 posts since Jun 2006
Reputation Points: 113
Solved Threads: 20
 

so C doesnt have bool defined that's why they need to define it like that?

number87
Junior Poster in Training
83 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

Yes. bool was added to the C++ specification in a later release.

However bool is a loose specification within Visual Studio. It allows you to assign other values then bool true false. If I'm converting a program over to the current compiler I'll use something like:

typedef enum
{
	bfalse = 0,
	btrue = 1
} tbool;			// Boolean!

#define bool  tbool
#define false bfalse
#define true  btrue


This is actually strong typechecking so easier to find mismatched boolean assignments as they'll cause compiler errors. Once found comment out and use the now standard bool. The macros override the compiler declarations.

wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You