Professional Documents
Culture Documents
CE144 OOPC Unit-07
CE144 OOPC Unit-07
UNIT-7
Operator Overloading
N. A. Shaikh
nishatshaikh.it@charusat.ac.in
Topics to be covered
Introduction
Defining Operator overloading
Overloading unary and binary operators
Overloading binary operator using friend function
Rules for overloading operators
Type Conversion
Operator overloading:
It is a compile-time polymorphism in which the
operator is overloaded to provide the special meaning
to the user-defined data type
In other words, giving the C++ operators such as +, *, ==
additional meanings when they are applied with user-
defined data types.
NOTE:
Operator functions must be either member functions(non-static)
or friend functions.
Friend function will have only one argument for unary
operators and two for binary operators.
Member function has no argument for unary operators
and only one for binary operators.
Unit 7: Operator Overloading Prepared By: Nishat Shaikh
8
Defining Operator Overloading
Example
+(s3=s1+s2)
==(s1<s2)
+=(s1+=s2)
Pounds=Kilograms * 2.20462262184878