简体   繁体   English

<error C2059: syntax error : 'constant'>用const int编译时

[英]<error C2059: syntax error : 'constant'> when compiling with const int

I am getting the following errors when compiling the below code: 编译以下代码时出现以下错误:

3>c:\hedge\hedge\hedge\AisTarget.h(22) : error C2059: syntax error : 'constant'
3>c:\hedge\hedge\hedge\AisTarget.h(22) : error C2238: unexpected token(s) preceding ';'

#if !defined(AisTarget_h)
#define AisTarget_h

#include "GeneralAviationItems.h"
#include <string>

namespace HEDGE {
    using namespace GeneralAviation; 

    class AisTarget : public WaypointLatLon {
        public:
            static const int NO_DATA = -1000; //here is the error
    };    
} // end namespace HEDGE

#endif

It is likely that NO_DATA is already defined as a macro elsewhere, and so it is expanding into something that does not agree with the compiler's notion of a variable name. 很可能NO_DATA已经被定义为其他地方的宏,因此它正在扩展到与编译器的变量名称概念不一致的东西。 Try re-naming NO_DATA to something else. 尝试将NO_DATA重新命名为其他内容。

If there were no such conflict, the code as it were would compile fine, as demonstrated here . 如果没有这种冲突,因为它是代码将编译罚款,这表现在这里

Even if this post has its age: The error can generally occur when multiple redefinitions, even regardless of upper/lower case, coexist. 即使这篇文章有它的年龄:当多个重新定义,即使不管大写/小写,共存时,通常也会发生错误。 This includes potential preprocessor definitions in the solution's .vcprojx file! 这包括解决方案的.vcprojx文件中潜在的预处理器定义! . Consider something like 考虑类似的事情

  <ItemDefinitionGroup>
    <ClCompile>
      <PreprocessorDefinitions>$(Configuration);%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
  </ItemDefinitionGroup>

in the above mentioned file. 在上面提到的文件中。 Now, having "Debug" and "Release" configurations you will most probably run into some problems and a potential source for the C2059 error. 现在,拥有“调试”和“释放”配置,您很可能会遇到一些问题,并且可能会导致C2059错误。 I experienced exaclty this dilemma. 我经历了这种两难困境。

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

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