0

私が書いたカスタム関数を使用して、カスタム構造体型のリストをソートしようとしていますが、エラーが発生します:

宣言されていない識別子の使用

struct myStruct
{
    int x1;
    int x2;
};

bool CompareData(const myStruct& a, const myStruct& b)
{
    if (a.x1 < b.x1) return true;
    if (b.x1 < a.x1) return false;

    // a=b for primary condition, go to secondary
    if (a.x2 < b.x2) return true;
    if (b.x2 < a.x2) return false;

    return false;
}

void sortingList ()
{
    std::list<myStruct> custom_dist;
    //...Fill list
    custom_dist.sort(CompareData); //Here i receive the error
}

これはエラーです:

ここに画像の説明を入力

入力パラメーターを期待しているように見えるため...

4

1 に答える 1

0

このコードは私にとってはうまくコンパイルされます。std からのリストを含めましたか? これは私がそれを構築する方法です: g++ -Wall main.cpp

#include <list>

struct myStruct
{
int x1;
int x2;
};

bool CompareData(const myStruct& a, const myStruct& b)
{
if (a.x1 < b.x1) return true;
if (b.x1 < a.x1) return false;

// a=b for primary condition, go to secondary
if (a.x2 < b.x2) return true;
if (b.x2 < a.x2) return false;

return false;
}

int main()
{
    std::list<myStruct> custom_dist;
    custom_dist.sort(CompareData);
    return 0;
}
于 2013-08-17T09:12:25.387 に答える