简体   繁体   English

枚举时的Visual Studio编译器错误

[英]Visual studio compiler errors at enum

I have the following code which compiles without errors under Linux and Mac OS X. I now want to compile the code with Windows, but I get a lot of errors in the following code segment: 我有以下代码,它们可以在Linux和Mac OS X下无错误地进行编译。我现在想用Windows进行编译,但是在以下代码段中出现了很多错误:

...
enum Type   
    {
        UPDATE = 0, DELETE = 1
    };
...

The error messages are these: 错误消息如下:

1>Request.hpp(48) : error C2143: syntax error : missing '}' before '('
1>Request.hpp(48) : error C2059: syntax error : '<L_TYPE_raw>'
1>Request.hpp(49) : error C2143: syntax error : missing ';' before '}'
1>Request.hpp(49) : error C2238: unexpected token(s) preceding ';'

What did I wrong, I am really confused, as this compiles without errors under Linux. 我做错了什么,我真的很困惑,因为它可以在Linux下正确编译。 What can cause this errors? 什么会导致此错误?

The solution is quite easy, but one need to find out that DELETE is a Macro defined in the windows header. 解决方案非常简单,但是需要发现DELETE是在Windows标头中定义的宏。

I now added #undef DELETE and it works fine. 我现在添加了#undef DELETE,它可以正常工作。

Type is an existing class. Type是一个现有的类。 You need to change the name or specify that it's a literal. 您需要更改名称或指定它是文字。

You could try enum @Type to specify a literal, though you may need to prefix it with @ elsewhere. 您可以尝试使用enum @Type指定文字,尽管您可能需要在其他位置以@作为前缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM