c++ - Cannot construct an std::map with a customer compare functor? -



c++ - Cannot construct an std::map with a customer compare functor? -

#include <map> using namespace std; class c { public: c(map<int,int> m) { } int operator()(int a, int b) { homecoming < b; } }; int main() { map<int, int> m; map<int, int, c> mymap(c(m)); mymap.insert(pair<int,int>(1,1)); }

why next error?:

main.cpp: in function 'int main()': main.cpp:16:11: error: request fellow member 'insert' in 'mymap', of non-class type 'std::map<int, int, c>(c)' mymap.insert(pair<int,int>(1,1));

here coliru link: http://coliru.stacked-crooked.com/a/0413a35d3177ef48

this illustration of vexing parse - function declaration, you'd expect object.

try this:

map<int, int, c> mymap((c(m)));

c++ g++ stdmap

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -