May 2012
Intermediate to advanced
679 pages
16h 56m
English
Just like unary operators, binary operators can also be overloaded. A binary operator takes two operands. The rule in operator overloading is that one of the operands must be an object. (Well in its absence, you are redefining what is 2 + 2. No language designer will allow you to do that.)
This leads to three distinct cases or types of binary operator overloading.
Case (1) Object + object
Case (2) Object + basic data type (say int )
Case (3) Basic data type (say int ) + object
Let us discuss all these cases one by one.
It is natural to assume that both objects belonging to same class. Consider that we want to overload operator + with both objects of class Complex. It will imply that ...
Read now
Unlock full access