[英]Error C2893 Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&…)'
[英]error C2893: Failed to specialize function template 'unknown-type std::less<void>::operator ()(_Ty1 &&,_Ty2 &&) const'
我編寫了一個函數,該函數將采用點的向量,點是一個結構,並將使用穩定排序對其進行排序,但出現以下錯誤:
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);
那么,你怎么想訂購你的觀點? 您如何知道一個點在排序時是否應該先於另一個點? 您是通過x坐標訂購的還是什么? 您需要告訴編譯器!
換句話說,您需要提供一個operator < 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.