14

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
3
  • Your #if !defined can be replaced with #ifndef btw. Commented Aug 2, 2012 at 16:44
  • Does it work if you replace static const int NO_DATA = -1000; with enum { NO_DATA = -1000 };? In that case, you have a very old compiler. Please don't tell us you're using Visual Studio 6 ;-) Commented Aug 2, 2012 at 16:44
  • using visual studio 2008 express. no worries guys, this is just for simulator. Commented Aug 2, 2012 at 17:07

2 Answers 2

33

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.

Sign up to request clarification or add additional context in comments.

3 Comments

That's why I don't use uppercase identifiers in C++. Too many reckless-named macros in standard libraries. windows.h is horrible
@kotlomoy: Yes, that is generally good practice. At a minimum, upper case identifiers should have some distinguishing prefix or postfix to avoid such collisions (preferably in mixed or lower case).
came here because of NO_ERROR, thanks winerror.h. NO_DATA is btw defined in WinSock2.h
5

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.

1 Comment

wow, this happened to me just now and thanks to your post, i was able to fix it in no time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.