SlidePub
Home
Categories
Login
Register
Home
General
Operator overloading
Operator overloading
KamleshMakvana
381 views
11 slides
Apr 03, 2018
Slide
1
of 11
Previous
Next
1
2
3
4
5
6
7
8
9
10
11
About This Presentation
Operator Overloading in C++.
Size:
496.24 KB
Language:
en
Added:
Apr 03, 2018
Slides:
11 pages
Slide Content
Slide 1
Classified e-Material ©Copyrights Charotar Institute of Technology, Changa 1
Department of Information Technology
Operator Overloading
CE 142: Object Oriented
Programming with C++
Kamlesh Makvana
Slide 2
Classified e-Material ©Copyrights Charotar Institute of Technology, Changa 2
Department of Information Technology
C++ Operator Overloading
One to type of polymorphism
Gives user defined meaning of operators
i.e. perform operations on user defined data
types.
Meaning of operator is already defined
by the compiler for built-in data types.
Redefine same for user defined data
types like objects.
Slide 3
Classified e-Material ©Copyrights Charotar Institute of Technology, Changa 3
Department of Information Technology
Why Operator Overloading
Make program more readable
c= add(c1,c2);
c= c1+c2;
z=add(mul(a,b),sub(x,y));
z=(a*b)+(x-y);
Slide 4
Classified e-Material ©Copyrights Charotar Institute of Technology, Changa 4
Department of Information Technology
How to overload Operator in C++
Create a operator functions
Operator functions could be a member
functions.
Operator functions could be a normal user
defined functions.
Slide 5
Classified e-Material ©Copyrights Charotar Institute of Technology, Changa 5
Department of Information Technology
Operator functions could be a
member functions
Slide 6
Classified e-Material ©Copyrights Charotar Institute of Technology, Changa 6
Department of Information Technology
Operator functions could be a
member functions
Slide 7
Classified e-Material ©Copyrights Charotar Institute of Technology, Changa 7
Department of Information Technology
Operator functions could be a
normal UDF.
Slide 8
Classified e-Material ©Copyrights Charotar Institute of Technology, Changa 8
Department of Information TechnologyOperator functions could be
a normal UDF.
Slide 9
Classified e-Material ©Copyrights Charotar Institute of Technology, Changa 9
Department of Information Technology
Rules for operator overloading
Only existing operators is overloaded. Can
not create new operators.
Overloaded operator must have at least one
operands.
Basic meaning of operator could not be
changed.
Some operators can not be overloaded like
dot(.), ::, ?:, sizeof, etc.
We can not use friend function to overload
some operators like =, (), [], ->.
Slide 10
Classified e-Material ©Copyrights Charotar Institute of Technology, Changa 10
Department of Information Technology
Rules for operator overloading
If operator function is friend function
Unary operator: one arguments.
Binary operator: two arguments.
If operator is non-static member function.
Unary operator: no arguments.
Binary operator: one arguments.
Left-hand operand must be a type of relevant type.
Binary arithmetic should explicitly return a value.
Slide 11
Classified e-Material ©Copyrights Charotar Institute of Technology, Changa 11
Department of Information Technology
Overloading Binary Addition
operator
Tags
c++
operator overloading in c++
rules for overloading in c++
Categories
General
Download
Download Slideshow
Get the original presentation file
Quick Actions
Embed
Share
Save
Print
Full
Report
Statistics
Views
381
Slides
11
Favorites
3
Age
2803 days
Related Slideshows
22
Pray For The Peace Of Jerusalem and You Will Prosper
RodolfoMoralesMarcuc
33 views
26
Don_t_Waste_Your_Life_God.....powerpoint
chalobrido8
36 views
31
VILLASUR_FACTORS_TO_CONSIDER_IN_PLATING_SALAD_10-13.pdf
JaiJai148317
33 views
14
Fertility awareness methods for women in the society
Isaiah47
30 views
35
Chapter 5 Arithmetic Functions Computer Organisation and Architecture
RitikSharma297999
29 views
5
syakira bhasa inggris (1) (1).pptx.......
ourcommunity56
30 views
View More in This Category
Embed Slideshow
Dimensions
Width (px)
Height (px)
Start Page
Which slide to start from (1-11)
Options
Auto-play slides
Show controls
Embed Code
Copy Code
Share Slideshow
Share on Social Media
Share on Facebook
Share on Twitter
Share on LinkedIn
Share via Email
Or copy link
Copy
Report Content
Reason for reporting
*
Select a reason...
Inappropriate content
Copyright violation
Spam or misleading
Offensive or hateful
Privacy violation
Other
Slide number
Leave blank if it applies to the entire slideshow
Additional details
*
Help us understand the problem better