我有一些問題,編譯這段代碼工作。我找不到錯誤。錯誤不是由於範圍或常量函數。我也嘗試將sort方法放在一個非常量函數中,併發生相同的錯誤。STD:排序不上向量
struct _Invoice {
unsigned int amm;
string id;
};
.
.
.
vector<_Invoice> Invoices;
.
.
.
bool invComp(const _Invoice &a, const _Invoice &b){
return a.amm < b.amm;
}
unsigned int MedianInvoice (void) const{
vector<_Invoice>tmpInvoices(Invoices);
sort(tmpInvoices.begin(), tmpInvoices.end(), invComp);
return (tmpInvoices.begin() + ceil((double)tmpInvoices.size()/2))->amm;
}
在此先感謝!
你忘了告訴我們你的'invComp'函數,這是這裏最重要的一件事。你也忽略了說你看到了什麼錯誤,你的輸入是什麼,你的期望輸出是什麼,你實際得到了什麼,等等。我們需要一個[MCVE]來幫助你。 – ShadowRanger
題外話:什麼是有關在C++標識符使用下劃線的規則?](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in- ac-identifier)提示:你正在破壞它們。 – user4581301
謝謝,我不知道這些規則。我只用了一兩個月的時間。 現在還有invCmp功能。 – totalolage