what does mean by "return dist>X.dist"? If dist is bigger than X.dist, return true?
You're right.
Operators aren't different from a normal member function. The compiler just execute the function when finds that operator.
You could try put an print statement and see what happens
bool operator < (nodo X) const{ std::cout << "Operator < called" << std::endl; return dist < X.dist; // I changed the sign because it looks more natural } // ... int main() { nodo smallnode(1,2,3); nodo bignode(4,5,6); std::cout << "First node Vs Second Node" << std::endl; if (smallnode < bignode) std::cout << "It's smaller!" << std::endl; else std::cout << "It's bigger!" << std::endl; }
nodeA < nodeBinstead ofnodeA.dist > nodeB.dist. That's what overloading operators is good for. It's an infix function notation fornodeA.operator<(nodeB)like you'd call any other member function.