( a*b + b*c ) / ( b*c ) Why is overloading better?
Operator overloading is mainly syntactical sugar, but without it that line would read:
Code:
div(sum(mult(a, b), mult(b, c)), mult(b, c))
It is also important when templates comes to play. For example, how would you write a function that would work for pointers and classes (iterators) if the iterators didn't provide the similar interface and operators as pointers? (like most functions in <algorithms>)
Overloading + usually looks like this:
Code:
MyClass operator+(const MyClass& lhv, const MyClass& rhv); //non-member
You can't overload operators for built-in types only. You can't take int a and int b and make + means something different for them.