c++ - 错误 C2893 : Failed to specialize function template 'unknown-type std::less<void>::operator ()(_Ty1 &&,_Ty2 &&) const'

标签 c++ sorting

我写了一个函数,它将接受一个点 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/

相关文章:

ajax - 使用 AJAX 搜索、排序

Java 多列条件排序

java - Gnomesort 仅适用于前两个字符串

C++ 快速排序实现,没有正确的输出

c# - C++11 有 C# 风格的属性吗?

c++ - RAII 和 C++ STL

c# - Hook Windows Server 2008 上的 SMB 文件操作

c - 选择排序和在 C 中使用 findMin 方法的问题

c++ - 重新分配给 const 引用

python - 排序列表时避免不必要的键评估