Operator overloading:It is one of the features of Object oriented programming which gives an extra ability to an operator to act on a User-defined operand(Objects).
Uses of Operator Overloading:
Extensability: An operator will act differently depending on the operands provided.
Operator is not limited to work only with primitive Data Type.
Above answer was rated as good by the following members: wael.salman, yzesong
RE: What is operator overloading?what r the advantages...
Operator overloading:It is one of the features of Object oriented programming which gives an extra ability to an operator to act on a User-defined operand(Objects).
Uses of Operator Overloading:
Extensability: An operator will act differently depending on the operands provided.
Operator is not limited to work only with primitive Data Type.
RE: What is operator overloading?what r the advantages...
The advantage to operator overloading is that it makes code much more readable. and You can override the conversion operators to allow your user-defined types to be converted to either built-in types or other user-defined types.
RE: What is operator overloading?what r the advantages...
Operators like + - * etc are internally unary / binary functions that take corresponding parameters. For example 3+4 is considered as +(3 4) where + is the function name. These functions(operators) come with a default implementation that takes the primitives(int float etc) as the parameters. If you would want these functions(operators) to work on objects of your own classes you may choose to implement those features by overloading these functions(operators).
Example: You may write a class named MyClass that will allow to add two objects of the same class. For this you may overload the + function(operator) as follows:
class MyClass {
void +(MyClass &myclass) {/*this class + another object of same class*/ }
RE: What is operator overloading?what r the advantages of operator overloading?
When the operator operates on the user defined data type or operands behaves same as it operates on inbuilt data type that mechanism is known as operator overloading. The operator that performs the specific task on inbuilt data type performs similar task upon the user defined data type.
int x 5 y 6 z; z x+y; ...../* addition operator acts on inbuilt data type for addition porpose. */
class nisi a1 a2 a3; a3 a1+a2; ..../* Here it is used to add two objects of class named nisi which is user defined data type. */