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