943,735 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 9773
  • C++ RSS
Aug 12th, 2009
0

typedef enum

Expand Post »
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

C++ Syntax (Toggle Plain Text)
  1. typedef enum {false, true} bool;
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
number87 is offline Offline
83 posts
since Jan 2008
Aug 12th, 2009
0

Re: typedef enum

bool, true, false are already keyword in C++. you don't need to define enum for it.
Reputation Points: 113
Solved Threads: 20
Junior Poster
Laiq Ahmed is offline Offline
147 posts
since Jun 2006
Aug 12th, 2009
0

Re: typedef enum

so C doesnt have bool defined that's why they need to define it like that?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
number87 is offline Offline
83 posts
since Jan 2008
Aug 12th, 2009
0

Re: typedef enum

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:

C++ Syntax (Toggle Plain Text)
  1. typedef enum
  2. {
  3. bfalse = 0,
  4. btrue = 1
  5. } tbool; // Boolean!
  6.  
  7. #define bool tbool
  8. #define false bfalse
  9. #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.
Last edited by wildgoose; Aug 12th, 2009 at 3:17 am.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Pointer Function problem
Next Thread in C++ Forum Timeline: Access the Class method via the pointer





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC