#include <map>
using namespace std;
class C {
public:
C(map<int,int> m) { }
int operator()(int a, int b) {
return a < b;
}
};
int main() {
map<int, int> m;
map<int, int, C> mymap(C(m));
mymap.insert(pair<int,int>(1,1));
}
为什么我会收到以下错误?:无法使用客户比较函数构造std :: map?
main.cpp: In function 'int main()':
main.cpp:16:11: error: request for member 'insert' in 'mymap', which is of non-class type 'std::map<int, int, C>(C)'
mymap.insert(pair<int,int>(1,1));
这里是coliru链接:http://coliru.stacked-crooked.com/a/0413a35d3177ef48
这是1小时内的第二个MVP问题 – 2014-11-06 13:07:17
@LightnessRacesinOrbit什么是MVP? – 2014-11-06 13:46:11
@NeilKirk:http://en.wikipedia.org/wiki/Most_vexing_parse – 2014-11-06 13:56:58