Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

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
like image 546
user1572019 Avatar asked Aug 02 '12 16:08

user1572019


2 Answers

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. Try re-naming NO_DATA to something else.

If there were no such conflict, the code as it were would compile fine, as demonstrated here.

like image 122
jxh Avatar answered Nov 14 '22 05:11

jxh


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!. 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. I experienced exaclty this dilemma.

like image 29
gilgamash Avatar answered Nov 14 '22 05:11

gilgamash