Operator Overloading
Operator overloading is one of the several exciting characteristics of C++ language. Operator overloading is a very important method which has enhanced the power of extensibility of C++ language. We have stated more than once in which C++ tries to make the user-defined data types behave in much the similar way as the built-in types. For example, C++ allows us to add two variables of user-defined types with the similar syntax which is applied to the basic type. The mechanism of providing such special meaning to an operator is called as operator overloading.
Operator overloading gives a flexible option for the creation of new definitions for most of the C++ language operators. We can almost make a new language of our own through the creative use of the function and operator overloading methods. We can overload all the C++ operators except the following:
1. Class member access operators (.,.*)
2. Scope resolution operator (::)
3. Size of operator (sizeof)
4. Conditional operator (?:)
the barred operators are very few when compared to the large number of operators, that qualify for the operator overloading definition.
While the semantics of an operator can be extended, we cannot modify its syntax, the grammatical rules which govern its use like as the number of operands, associatively and precedence.
For instance, the multiplication operator will enjoy higher precedence than the addition operator. Note, when an operator is overloaded, its actual meaning is not lost. For instance, the operator +, that have been overloaded to add two vectors; could still be used to add two integers.