Operator overloading is one feature with c++ which has been induced with no real object oriented philosophy to support. But its one feature every java guys crave for. Why? The answer is obvious. Better readability and ‘makes-sense’. Let me clarify this point.
Lets assume2 objects of class type Point which need to add the corresponding x & y coordinated and returns a Point object
Lets try implement this with an Add( )member function
class Point
{
int x;
int y;
Public:
Point add(Point P1,Point P2);
};
So when ever you want to add two points this is what you will be doing and it works fine.
Point Result = varPoint.Add(Point1,Point2);
Now lets see how the same can be achieved using overloading The ‘+’ operator using operator overloading
class Point
{
int x;
int y;
Public:
Point operator+ (Point & a, Point & b);
};
So when you want to add two points all you have to do is
Point PointResult = Point1 + Point2;
Now its up to you to interpret which style looks “normal” !!
Talking about operator overloading it will be of interest to imagine about following scenarios
- Operator overloading functions as Friends
- Making operator overloading functions global
Now it smells nonsense, But its not!
You dig into any frame work classes you will find plenty of the above two species of operator over loaders. Which follows the next big question…WHY?

