遭遇的问题是:
原代码为:
struct Node {
int cost;
int city;
int stops;
bool operator>(const Node& n) { return cost > n.cost; }
};
但编译出错,问题在于操作符重载。
解决:将操作符重载改为:
bool operator>(const Node& n) const{ return cost > n.cost; }
原因分析:可能由于该类的对象作为参数传入操作符函数时,也需要const约束。
箴言录:
与人不求备,检身若不及。