我試圖使用STL的sort()中的一類功能。我想排序結構的數組看起來像這樣:比較與STL的sort()
struct foo{
double num;
std::string s;
};
有一個比較函數是這樣的:
bool aGreaterThanb(foo a, foo b){
if (a.num > b.num){
if(a.num == b.num){
if (anotherOutsideComparison(a.s, b.s)){
return true;
}
}
else
return true;
}
else
return false;
}
但我不知道我該怎麼格式化這個得到它編譯。我應該如何格式化以便我可以撥打sort(fooarray[0], fooarray[end], aGreaterThanb);
? (一個例子將是巨大的)
它應該按原樣工作。你的代碼中只有一個語法錯誤(在返回true之後,你錯過了一個大括號'}')。對我來說,這是排列開放和關閉大括號的好理由。 –