2

I have header file. I want a map object added to one of the structures. So I included

#include<map> 

and compiled the program (note I did not use map object I just included it) and I got the following error

/usr/include/c++/4.7/bits/stl_map.h:115:28: error: macro "value_compare" requires 2 arguments, but only 1 given /usr/include/c++/4.7/bits/stl_map.h:733:45: error: macro "value_compare" requires 2 arguments, but only 1 given In file included from /usr/include/c++/4.7/map:62:0, from ../optimizer_types.h:16, from ../main.cpp:20: /usr/include/c++/4.7/bits/stl_multimap.h:115:28: error: macro "value_compare" requires 2 arguments, but only 1 given /usr/include/c++/4.7/bits/stl_multimap.h:656:45: error: macro "value_compare" requires 2 arguments, but only 1 given In file included from /usr/include/c++/4.7/map:61:0, from ../optimizer_types.h:16, from ../main.cpp:20: /usr/include/c++/4.7/bits/stl_map.h:113:11: error: invalid use of non-static data member 'std::map<_Key, _Tp, _Compare, _Alloc>::value_compare::comp' /usr/include/c++/4.7/bits/stl_map.h:116:4: error: from this location /usr/include/c++/4.7/bits/stl_map.h:116:9: error: '__c' was not declared in this scope /usr/include/c++/4.7/bits/stl_map.h:116:12: error: a function call cannot appear in a constant-expression /usr/include/c++/4.7/bits/stl_map.h:116:12: error: expected ';' at end of member declaration /usr/include/c++/4.7/bits/stl_map.h:116:14: error: expected unqualified-id before '{' token /usr/include/c++/4.7/bits/stl_map.h: In member function 'std::map<_Key, _Tp, _Compare, _Alloc>::value_compare std::map<_Key, _Tp, _Compare, _Alloc>::value_comp() const': /usr/include/c++/4.7/bits/stl_map.h:733:46: error: expected primary-expression before ';' token In file included from /usr/include/c++/4.7/map:62:0, from ../optimizer_types.h:16, from ../main.cpp:20: /usr/include/c++/4.7/bits/stl_multimap.h: At global scope: /usr/include/c++/4.7/bits/stl_multimap.h:113:11: error: invalid use of non-static data member 'std::multimap<_Key, _Tp, _Compare, _Alloc>::value_compare::comp' /usr/include/c++/4.7/bits/stl_multimap.h:116:4: error: from this location /usr/include/c++/4.7/bits/stl_multimap.h:116:9: error: '__c' was not declared in this scope /usr/include/c++/4.7/bits/stl_multimap.h:116:12: error: a function call cannot appear in a constant-expression /usr/include/c++/4.7/bits/stl_multimap.h:116:12: error: expected ';' at end of member declaration /usr/include/c++/4.7/bits/stl_multimap.h:116:14: error: expected unqualified-id before '{' token /usr/include/c++/4.7/bits/stl_multimap.h: In member function 'std::multimap<_Key, _Tp, _Compare, _Alloc>::value_compare std::multimap<_Key, _Tp, _Compare, _Alloc>::value_comp() const': /usr/include/c++/4.7/bits/stl_multimap.h:656:46: error: expected primary-expression before ';' token 

As an experiment I moved the include to a cpp file and it was compiling properly.

What could be the reason

18
  • 1
    "macro "value_compare" requires " looks like you have a macro called value_compare which interferes with the library internals Commented Nov 21, 2012 at 16:27
  • Do you try to use clang with gcc STL? Commented Nov 21, 2012 at 16:28
  • @PlasmaHH That function is in this file /usr/include/c++/4.7/bits/stl_map.h Commented Nov 21, 2012 at 16:31
  • @MateuszPusz No just gcc Commented Nov 21, 2012 at 16:31
  • 1
    @PlasmaHH That's almost certainly the case. Some file included earlier has defined this macro---practically speaking, this means that that file cannot be included in a C++ program. Commented Nov 21, 2012 at 16:32

1 Answer 1

3

Try this:

#ifdef value_compare #undefine value_compare // std::map header doesn't like this #endif #include <map> 

It's not very flexible (or pretty) but it should get you through this :(

Edit: Either way, the problem is not including map, but the earlier include/code that defined value_compare macro. Is it a C header? (I doubt a C++ would define a macro with this name, as value_compare is an important part of the C++ standard library).

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.