枚举中的Visual studio编译器错误

Visual studio compiler errors at enum

本文关键字:编译器 错误 studio Visual 枚举      更新时间:2023-10-16

我有以下代码,在Linux和Mac OS x下编译没有错误。我现在想用Windows编译代码,但我在以下代码段中得到很多错误:

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

错误信息如下:

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 ';'

我错了什么,我真的很困惑,因为这在Linux下编译没有错误。什么会导致这些错误?

解决方案很简单,但需要找出DELETE是在windows头文件中定义的宏。

我现在添加#undef DELETE,它工作得很好

Type是一个已存在的类。您需要更改名称或将其指定为文字。

您可以尝试使用enum @Type来指定文字,尽管您可能需要在其他地方使用@作为前缀。