/** * Demonstration of operator overloading * CS 2240 * University of Vermont * Egbert Porcupine * 2020-Jul-03 */ #include "Foo.h" /** * Constructor * @param data int */ Foo::Foo(int data) { this->data = data; } /** * Overload < * Notice we only use "friend" in the class declaration in the header file * @param lhs Foo * @param rhs Foo * @return bool */ bool operator < (const Foo& lhs, const Foo& rhs) { return lhs.data < rhs.data; } /** * Overload > * Notice we only use "friend" in the class declaration in the header file * @param lhs Foo * @param rhs Foo * @return bool */ bool operator > (const Foo& lhs, const Foo& rhs) { return lhs.data > rhs.data; } /** * Overload <= * Notice we only use "friend" in the class declaration in the header file * @param lhs Foo * @param rhs Foo * @return bool */ bool operator <= (const Foo& lhs, const Foo& rhs) { return lhs.data <= rhs.data; } /** * Overload >= * Notice we only use "friend" in the class declaration in the header file * @param lhs Foo * @param rhs Foo * @return bool */ bool operator >= (const Foo& lhs, const Foo& rhs) { return lhs.data >= rhs.data; } /** * Overload == * Notice we only use "friend" in the class declaration in the header file * @param lhs Foo * @param rhs Foo * @return bool */ bool operator == (const Foo& lhs, const Foo& rhs) { return lhs.data == rhs.data; } /** * Overload != * Notice we only use "friend" in the class declaration in the header file * @param lhs Foo * @param rhs Foo * @return bool */ bool operator != (const Foo& lhs, const Foo& rhs) { return lhs.data != rhs.data; }