The following code example is taken from the book
Object-Oriented Programming in C++
by Nicolai M. Josuttis, Wiley, 2002
© Copyright Nicolai M. Josuttis 2002
// include header file of the class
#include "frac.hpp"
//...
/* operator <
* - new: global friend function
*/
bool operator < (const Fraction& a, const Fraction& b)
{
// because the denominator can not be negative, the following is sufficient:
return a.numer * b.denom < b.numer * a.denom;
}
//...