C++ 错误 C2059:语法错误“常量”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18614221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error C2059: syntax error 'constant'
提问by RayOldProf
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:
我在 main.c 中有我的主要功能。如果我将扩展名更改为 main.cpp,则会出现以下错误:
Error C2059: syntax error 'constant'
Im using visual c++, any Idea why`?
我正在使用 Visual C++,知道为什么吗?
回答by juanchopanza
true
and false
are keywords representing constant values in C++. You cannot use them to name things such as enum values.
true
和false
是在 C++ 中表示常量值的关键字。您不能使用它们来命名诸如枚举值之类的东西。
As an example, the following would compile
例如,以下将编译
enum { false_, true_ };
int main() {}
回答by haccks
false
and true
are reserve words in C++. You can't redefine it as variable.
false
和true
是 C++ 中的保留字。您不能将其重新定义为变量。