30-11-2012, 11:48 AM
Operator overloading in C++
1Operator overloading.pptx (Size: 172.38 KB / Downloads: 24)
Defination
Operator overloading is one of the exciting features of c++ language.It is an important technique that has enhanced the power of extensibility of c++.
As we know earlier that c++ allows to make the user-defined data types behave in much the same way as the built-in types. It means that c++ has the ability to provide the operators with a special meaning for a data type.
“The process of giving such special meaning to an operator is known as operator overloading”.
Operator overloading provides an option for the creation of new definition for most of the c++ operators.
Operator overloading process…
Create a class that defines the data type that is to be used in the overloading operator.
Declare an operator function operator op() in the public part of the class. It may be a member function or a friend function.
Define the operator function to implement the required operators.
Rules for overloading operator…
New operator cannot be created.
The overloaded operator must have at least one operand that is userdefind.
Basic meaning of operator cannot be changed.
Overloaded operators follow the syntax rules of the original operator.
Unary operators does not take explicit argument*.
Binary operators can take one explicit argument*.