const
을 bool operator<(const Node& otherNode) //const
에 넣지 않으면 오류가 발생하는 이유는 무엇입니까?C++ 오버로드 연산자 <오류
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;
}
};
작동했지만 모든 운영자가 const 여야 만하는지 의심 스러웠습니다. 지금은 이해. 감사. – BRabbit27