Why am I getting “error: expected '}'” in C++ but not in C?

前端 未结 3 510
轻奢々
轻奢々 2021-01-21 07:34

I\'m getting \"error: expected \'}\'\" where the \'^\' is pointing when I compile in the following C++ source:

typedef enum { false, true } Boolean;         


        
3条回答
  •  离开以前
    2021-01-21 08:27

    To solve this you need to do:

    #ifdef __cplusplus
      typedef bool Boolean;
    #else
      typedef enum { false, true } Boolean;
    #endif
    

    That way, you are not trying to use C++ keywords (true and false) in an enum.

提交回复
热议问题