Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error C2059: syntax error 'constant' [duplicate]

I have the following code in a header file:

enum {false,true};

and I have my main function in main.c. if I change the extention to main.cpp I get the following error:

Error C2059: syntax error 'constant' 

Im using visual c++, any Idea why`?

like image 371
RayOldProf Avatar asked Dec 16 '22 06:12

RayOldProf


1 Answers

true and false are keywords representing constant values in C++. You cannot use them to name things such as enum values.

As an example, the following would compile

enum { false_, true_ };

int main() {}
like image 157
juanchopanza Avatar answered Dec 17 '22 20:12

juanchopanza