重载operator <为优先级队列

Ste*_*ing 5 c++ operator-overloading priority-queue operators conditional-operator

我试图建立一个像我这样的类的优先级队列 -

std::priority_queue<Position> nodes;
Run Code Online (Sandbox Code Playgroud)

我在这样的位置重载了<运算符 -

bool Position::operator<(Position& right) {
    return (fvalue < right.getFValue());
}
Run Code Online (Sandbox Code Playgroud)

但是,每当我尝试编译时,我都会收到此错误消息,指出<运算符未过载 -

error: no match for ‘operator<’ in ‘__x < __y’
position.h:30: note: candidates are: bool Position::operator<(Position&)
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?任何帮助表示赞赏.

Ben*_*igt 13

关系运算符不应更改操作数.尝试:

bool Position::operator<(const Position& right) const {
Run Code Online (Sandbox Code Playgroud)

我的猜测是,__x或者__y(或两者)都是const.你不能调用非const成员函数上__x,如果是const,你也可以不通过__yright,如果参数__yconstright不是.