不确定我是否在某个地方有一个简单的打字错误,但我在排序元组时遇到了问题。
所以,我的头像是这样的:
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);
}
}
主要是从评论转发
将您的实现更改为:
class Messages::MessageImpl{
private:
std::deque<boost::tuple<unsigned int, unsigned int> > messages;
static 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(), &MessageImpl::msg_sort_criteria);
}
};