我写了一个函数,它将接受一个点 vector ,点是一个结构,并将使用稳定排序对其进行排序,我得到以下错误:
Error 1 error C2893: Failed to specialize function template 'unknown-type std::less<void>::operator ()(_Ty1 &&,_Ty2 &&) const'
这就是我的程序应该做的:
in:
5 8
3 6
10 9
8 11
7 4
和显示:
out:
3 6
5 8
7 4
8 11
10 9
这是我的代码:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct points
{
int a, b;
};
int main()
{
int nbrDeLignes = 0;
cin >> nbrDeLignes;
vector<points> tab(nbrDeLignes);
for (int i = 0; i < nbrDeLignes; i++)
{
points p;
cin >> p.a >> p.b;
tab.push_back(p);
}
//stable_sort(tab.begin(), tab.end());
for (const points &point : tab)
{
cout << point.a << " " << point.b << endl;
}
return 0;
}
任何帮助请;
最佳答案
stable_sort
不知道如何对您的 struct
进行排序因为没有为它定义比较运算符。你要么需要制作 points
一个class
并覆盖 <
运营商,或提供 stable_sort
具有比较功能,例如。
bool compare_points(point p1, point p2)
{
return p1.a < p2.a;
}
stable_sort(tab.begin(), tab.end(), compare_points);
关于c++ - 错误 C2893 : Failed to specialize function template 'unknown-type std::less<void>::operator ()(_Ty1 &&,_Ty2 &&) const' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23305726/