5
不知道我是否有一個簡單的錯字,但我遇到了排序元組deque的問題。排序升壓元組deque
所以,我的雙端隊列是這樣的:
std::deque<boost::tuple<unsigned int, unsigned int> > messages;
然後,我有我的電話進行排序:
sort(messages.begin(), messages.end(), msg_sort_criteria);
我的排序功能:
bool msg_sort_criteria(boost::tuple<unsigned int, unsigned int> lhs, boost::tuple<unsigned int, unsigned int> rhs)
{
return boost::get<1>(lhs) < boost::get<1>(rhs);
}
會發生什麼我在stl_heap.h和stl_algo.h中遇到錯誤。 例如,
稱爲對象類型「
<bound member function type>
」不是功能或 函數參數。
編輯:
爲了澄清,這是一類的私有成員中的所有發生。
class Messages::MessageImpl{
private:
std::deque<boost::tuple<unsigned int, unsigned int> > messages;
bool msg_sort_criteria(boost::tuple<unsigned int, unsigned int> lhs, boost::tuple<unsigned int, unsigned int> rhs)
{
return boost::get<1>(lhs) < boost::get<1>(rhs);
}
void fn()
{
sort(msg_queue_.begin(), msg_queue_.end(), msg_sort_criteria);
}
}
是'msg_sort_criteria'自由函數或成員函數?如果前者,你需要顯示更多的代碼;如果是後者,使它成爲'static'並且改變'sort(messages.begin(),messages.end(),msg_sort_criteria);'sort(messages.begin(),messages.end(),&myClassName :: msg_sort_criteria );'。 – ildjarn 2012-07-17 18:00:25
所有這些代碼都在類的私有成員中進行。我會相應地更新 – espais 2012-07-17 18:05:34
你是否故意只通過'tuple'的第一個成員進行排序?如果你不關心第一個元素相等的項目的順序,你可以使用默認的元組'operator <',並且根本不打擾排序謂詞。 – 2012-07-17 18:10:09