Ok so I have 1 user-defined type named fraction
and it represents and ordinary fraction with a numerator and denominator. Here is the code:
class Fr
bool operator<(Fraction& first,Fraction& second)
The problem is that your overload of operator<
only accepts non-const arguments, but the algorithm is trying to compare a constant reference to a Fraction
with the elements in your container.
Since operator<
does not modify the contents of the compared objects, it should take them by const reference:
bool operator<(Fraction const & first,Fraction const & second)
Consider this code:
Fraction a, b;
bool res = (a < b);
The second line is essentially a call to
bool res = a.operator<(b);
bool operator<(const Fraction&) const
to make the sorting implementation happy or just go with the first suggestion above - be const-correct with bool operator<(const Fraction& a, const Fraction& b)