我需要对std :: pair的deque进行排序,然后打印出原始未排序的迭代器值,但是当我尝试使用以下代码时:
// I have used pii instead of pair<int,int> by using typedef
inline bool comparison(pii & lval, pii & rval) {
return (lval.first < rval.first);
} // and a few lines down
sort(v.begin(),v.end(), comparison);
我收到以下错误:
错误C2664:'bool(pii&amp;,pii&amp;)':无法将参数2从'const int'转换为'pii&amp;'
我似乎无法理解我哪里出错了,有人能弄明白这个错误吗? 如果您想查看完整代码,请点击此处:
#include <cstdio>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
inline void get_input(deque<pii> place, const int & size) {
pii temp;
for (int i = 0; i < size; ++i) {
scanf("%d", &temp.first);
temp.second = i;
place.push_back(temp);
}
}
inline bool comparison(pii & lval, pii & rval) {
return (lval.first < rval.first);
}
int main() {
int n;
scanf("%d", &n);
deque<pii> v1, v2;
get_input(v1, n);
get_input(v2, n);
sort(v1.begin(), v1.end(), comparison);
sort(v2.begin(), v2.end(), comparison);
/* I am aware that the part where I print the values of
the iterators is missing, I didn't want to add unimportant
bulk to the question */
return 0;
}