Title: C++ & Oops
Title: C++ & Oops
Title: C++ & Oops
SESSION 10
OPERATOR OVERLOADING
The mechanism of giving special meanings to
an operator is known as Operator Overloading.
This is one of the exciting features of C++.
This technique has enhanced the power of
extensibility of C++.
This technique permits to add two user –
defined variables with the same syntax that is
applied to basic types.
Provides the new definitions for most of the C+
+ operators .
We can overload all the C++ operators
except
Class member access operators ( . , .* ).
Scope resolution operator ( : : )
Sizeof operator ( sizeof )
Conditional operator ( ? : )
DEFINING OPERATOR OVERLOADING
Return type class name :: operator op (arg –
list )
{
function body
}
return type is the type of the value returned
by the function
op is the operator being overloaded.
The op is preceded by the key word
operator
operator op is the function name
Operator function must be either
member function or friend function
RULES FOR OVERLOADING OPERATORS