Error c2059 синтаксическая ошибка константа

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

Fantastic Mr Fox's user avatar

asked Aug 2, 2012 at 16:41

user1572019's user avatar

3

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.

answered Aug 2, 2012 at 16:45

jxh's user avatar

jxhjxh

69.1k8 gold badges110 silver badges194 bronze badges

3

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.

answered Apr 21, 2016 at 7:32

gilgamash's user avatar

gilgamashgilgamash

86211 silver badges31 bronze badges

1

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

Fantastic Mr Fox's user avatar

asked Aug 2, 2012 at 16:41

user1572019's user avatar

3

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.

answered Aug 2, 2012 at 16:45

jxh's user avatar

jxhjxh

69.1k8 gold badges110 silver badges194 bronze badges

3

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.

answered Apr 21, 2016 at 7:32

gilgamash's user avatar

gilgamashgilgamash

86211 silver badges31 bronze badges

1

Search code, repositories, users, issues, pull requests…

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

  • Remove From My Forums
  • Question

  • error C2059: syntax error : 'constant'
    
    HI
    i have a file named SharedCount.hxx.
    i this file i have a class that ovveride operator new.
    
    problem with this is when i want to use this class compiler generate this error
    
    error C2059: syntax error : 'constant'
    
    and error line point to operator new overloading.
    
    exactly this file is modified version of boost shared_ptr.i use these file in another projects without any problem(vs c++ 2010).
    
    please help me to solve this error.
    unfortunately original code is very very long to be posted here but if it is required i will post it compeletly
    *******************************************SharedCount.hxx Snippet****************************************************
    
        #include "stdafx.h"
        #include <memory> // std::auto_ptr, std::allocator
        #include <functional> // std::less
        #include <exception> // std::exception
        #include <new> // std::bad_alloc
        #include <typeinfo> // std::type_info in get_deleter
        #include <cstddef> // std::size_t
        #include "ILock.hxx"
        #include "ILMutex.hxx"
        template<class P, class D> class ICORE_API sp_counted_base_impl: public sp_counted_base
        {
        private:
        P ptr; // copy constructor must not throw
        D del; // copy constructor must not throw
        sp_counted_base_impl(sp_counted_base_impl const &);
        sp_counted_base_impl & operator= (sp_counted_base_impl const &);
        typedef sp_counted_base_impl<P, D> this_type;
        public:
        // pre: initial_use_count <= initial_weak_count, d(p) must not throw
        sp_counted_base_impl(P p, D d): ptr(p), del(d)
        {
        }
        virtual void dispose() // nothrow
        {
        del(ptr);
        }
        virtual void * get_deleter(std::type_info const & ti)
        {
        return ti == typeid(D)? &del: 0;
        }
        void * operator new(size_t)
        {
        return std::allocator<this_type>().allocate(1, static_cast<this_type *>(0));
        }
        void operator delete(void * p)
        {
        std::allocator<this_type>().deallocate(static_cast<this_type *>(p), 1);
        }
        };

    #WebCan Video Conference System Based ON SL#

Answers

  • Then it must be some other file (not yours) where the ‘new’ is redefined.

    No, the error is related to ‘#define new …’ only.

    You could:

    1) Seach for ‘#define new’ in files that are included. To trace the included files,
    set «Show Includes» setting in C/C++ properties of your project. When building, the Output Windows will contain all that files. Find your error in the ‘Output Window’ and search the related ‘included’ files
    for ‘#define new’.

    OR

    2) Exclude some files from building and comment-out portions of your code until the problem disappears

    OR

    3) Create a new project and reproduce the problem with minimum amount of code. Next, use steps (1) and (2) to find the problem.

    OR

    4) Place

    #undef new 

    to the top of your file. But I’m not sure it will work as the root cause of that problem is still there.

    • Marked as answer by

      Monday, July 16, 2012 8:53 AM

  • Amir110 wrote:

    i test it and error trigers during bulding.

    but i never override operator new in a whole of project except in  SharedCount.hxx.

    Put this line near the beginning of SharedCount.hxx:

    #define new ANYTHING

    You would get an error about macro redifinition. The error message would  point to the spot of the previous definition. This way, you’ll find out  where new is defined as a macro.


    Igor Tandetnik

    • Proposed as answer by
      Grigoriy Chudnov
      Sunday, July 15, 2012 7:34 PM
    • Marked as answer by
      Amir110
      Monday, July 16, 2012 8:53 AM

I want to read and print the first two lines from a text file.
Problem is, I get the error: error c2059: syntax error: constant and it points to the first line in my text file.
Any ideas?

The file.txt:

5
5
3
1 1 1 0 0
0 1 0 0 1
0 1 0 1 0
1 0 1 0 1
1 1 0 1 1

The code:

#include <stdio.h>
#include <stdlib.h>

int main() {
    FILE *fp;
    int line, col, gen;
    fp = fopen("file.txt", "rt");
    fscanf(fp, "%d\n,%d\n", &line, &col);
    printf("line: %d,  col: %d\n", line, col);
    fclose(fp);
    return 0;
}

asked Dec 11, 2014 at 10:42

Avital's user avatar

8

Visual Studio will compile every file in your project. This includes file.txt, if you have added it as a file to your project.

To prevent Visual Studio from compiling this, you need to tell Visual Studio it’s a ‘Content’ file. Take a look at File Properties at Build Action Property.

Content — The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file.

answered Dec 11, 2014 at 11:02

bzeaman's user avatar

bzeamanbzeaman

1,12811 silver badges28 bronze badges

1

Понравилась статья? Поделить с друзьями:
  • Error 80004005 неопознанная ошибка elsa что делать
  • Error 601 battery как убрать ошибку
  • Error 6 prometheus ошибка crossout
  • Error load settings как исправить ошибку при запуске
  • Error 501 на котле аристон ошибка