【发布时间】:2012-12-18 14:05:30
【问题描述】:
当我没有将const 放入函数bool operator<(const Node& otherNode) //const 时,为什么会收到错误消息?
stl_algo.h:91: error: passing 'const Node' as 'this' argument of 'bool Node::operator<(const Node&)' discards qualifiers
所有重载的运算符都应该是常量吗?
class Node {
public:
double coordinate;
bool operator==(const Node& other) const{
return coordinate == other.coordinate;
}
bool operator<(const Node& other) const{
return coordinate < other.coordinate;
}
};
【问题讨论】:
标签: c++ operator-overloading constants