overloading operators

Operators are unary binary or tertiary.

when we overload operator do we need to consider this fact and if so how to determine in code

do overloading operators need to be of a class

do they always need to return type and if so what type

thanks
do overloading operators need to be of a class

the most operatos can be overloaded as non-member operators.
This approach is most likely to be prefered because it gives you more options but some of them can only be implemented as member-operators.

do they always need to return type and if so what type

No but for there are "standard ways".
as for operator+ you should allways return either void or a copy of the class.
as for operator+= you should return a copy of *this.

the rational operators should return a bool (that's what they are here for after all)

Here is a list of all operators and their "standard implementation" as member and non-member functions:
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
Topic archived. No new replies allowed.