#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