优先级队列

我正在尝试将这样创建的类的优先级队列-
std::priority_queue<Position> nodes;
我在这样的Position中重载了<运算符-
bool Position::operator<(Position& right) {
    return (fvalue < right.getFValue());
}
但是,每当我尝试编译时,我都会收到此错误消息,指出<运算符未过载-
error: no match for ‘operator<’ in ‘__x < __y’
position.h:30: note: candidates are: bool Position::operator<(Position&)
我在这里想念什么?任何帮助表示赞赏。     
已邀请:
        关系运算符不应更改操作数。尝试:
bool Position::operator<(const Position& right) const {
我的猜测是
__x
__y
(或两者)均为both6 are。如果
const
不能在
__x
上调用非常量成员函数,如果-5ѭ是
const
right
不是,则不能将
__y
作为
right
参数传递。     
         最好不要为了满足集合而重载比较运算符。 (http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Operator_Overloading)。如果可能的话,最好使用比较器对象或函数。如果您的操作员定义了这些对象的内部排序方式,而不是仅定义它们在队列中的优先级,那么就可以了。但是如果不是这样,如果另一个开发人员在另一个上下文中使用您的运算符,您可能会遇到麻烦。 我不确定ѭ14是什么,但是可能没有为它定义
operator <
。     

要回复问题请先登录注册