•Operator overloading is the process of enabling existingC++’s operators to work with class objects.
Contributes to C++’s extensibility•Examples:
bitwise left-shift operator and stream insertionoperator –>>
bitwise right-shift operator and stream extractionoperator –+ & -
overloaded to perform differently depending ontheir context in integer, floating-point arithmetic andpointer arithmetic
•In C++, most operators can be overloaded to besensitive to the context in which they are used. Thecompiler generates the appropriate code based on themanner in which the operator is used.Compiler candistinguish between overloaded functions by looking atthe data type of their arguments.•Operator overloading has clearer notion thancorresponding explicit functions calls•Avoid excessive or inconsistent use of operator overloading as this can make program cryptic anddifficult to program
Use when usage is obvious –similar meaning & same syntax.