This is what I've got so far. It works great, except I need help figuring out how to use the operator> overload via different classes. Can anyone help? https://godbolt.org/z/arsqWK5qE
#Trying to compare members of different classes to identify which is larger? Any ideas?
7 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
Should be useful here
Overloading the Less Than Operator
The less than operator returns true iff one object less than the other. If it establishes a strict weak ordering, it makes a type LessThanComparable, which allows using the type in a std::map, in std::sort and other algorithms.
Example
struct point {
int x, y;
// explicit defaulting since C++20
bool operator>(const point&) const = default;
};
// can also be defined outside the class
bool operator<(point a, point b) {
return a.x < b.x ||
a.x == b.x && a.y < b.y;
} ```
See Also
:cppreference: Comparison Operators
@umbral ore
!solved