I am trying to make a priority queue of a class I made like this -
std::priority_queue<Position> nodes;
I overloaded the < operator in Position like this -
bool Position::operator<(Position& right) {
return (fvalue < right.getFValue());
}
However, whenever I try to compile I get this error message saying the < operator is not overloaded -
error: no match for ‘operator<’ in ‘__x < __y’
position.h:30: note: candidates are: bool Position::operator<(Position&)
What am I missing here? Any help is appreciated.
Relational operators shouldn't change the operands. Try:
bool Position::operator<(const Position& right) const {
My guess is that either __x or __y (or both) are const. You can't call a non-const member function on __x if it's const, also you can't pass __y as the right parameter if __y is const and right is not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With