2013-08-17 55 views
0

我想排序的自定義結構類型的列表,自定義函數我寫的,但給我一個錯誤:使用未聲明的標識符的排序列表的自定義功能

Use of undeclared identifier

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 
} 

這是錯誤:

enter image description here

怎麼一回事,因爲似乎希望輸入參數...

+0

你能發佈完整的錯誤信息嗎? – MrMage

+0

我添加一個圖像的錯誤... – Piero

+0

發佈構建日誌... – MrMage

回答

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; 
}