Error C2059: syntax error "constant"

I have the following code in the header file:

enum {false,true}; 

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

 Error C2059: syntax error 'constant' 

I use visual C ++, any idea why`?

+4
source share
2 answers

true and false are keywords representing constant values ​​in C ++. You cannot use them to denote things like enumeration values.

As an example, the following:

 enum { false_, true_ }; int main() {} 
+11
source

false and true are fallback words in C ++. You cannot override it as a variable.

+1
source

Source: https://habr.com/ru/post/1500533/


All Articles