Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
11Activity
0 of .
Results for:
No results containing your search query
P. 1
C++ Operator Overloading

C++ Operator Overloading

Ratings:

4.0

(1)
|Views: 4,190|Likes:
Published by zainvi.sf6018
Extremely useful presentation on Operator Overloading (An powerful feature of C++).
More informative material available on:
http://computer-science-notes.blogspot.com
Extremely useful presentation on Operator Overloading (An powerful feature of C++).
More informative material available on:
http://computer-science-notes.blogspot.com

More info:

Published by: zainvi.sf6018 on Apr 10, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PPT, PDF, TXT or read online from Scribd
See more
See less

11/25/2012

pdf

text

original

 
C++
Operator OverloadingSource: How to C++ byDeitel & DeitelMore notes available at:
http://cplusplus-naturally.blogspot.com/
 
Introduction
Operator overloading is the process of enabling existingC++’s operators to work with class objects.
Contributes to C++’s extensibilityExamples:
 –<<
bitwise left-shift operator and stream insertionoperator  –>>
bitwise right-shift operator and stream extractionoperator  –+ & -
overloaded to perform differently depending ontheir context in integer, floating-point arithmetic andpointer arithmetic
In C++, most operators can be overloaded to besensitive to the context in which they are used. Thecompiler generates the appropriate code based on themanner in which the operator is used.Compiler candistinguish between overloaded functions by looking atthe data type of their arguments.Operator overloading has clearer notion thancorresponding explicit functions callsAvoid excessive or inconsistent use of operator overloading as this can make program cryptic anddifficult to program
Use when usage is obvious –similar meaning & same syntax.
 
Introduction – Contd…
C++ is type-focus and type-sensitive. It is operator richlanguage – built-in & those defined to work with user-defined classes.Prototype:
Return type operator<operator-to-be-overloaded>(parameter list){ … }type
if not ‘void’ then –Create a temp object (if object to be returned) to use asreturn value. –Use nameless initialized temp object (returncounter(count)) –Return original object using ‘this’
To use an operator on class objects, that operator mustbe overloaded – with two exceptionsOperators ‘=‘ and ‘&’ can be used with any class withoutexplicit overloading. The default behaviour of ‘=‘ ismember-wise assignment and ‘&’ is used to returnaddress of the object in memory.

Activity (11)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Anurag Dwivedi liked this
Chandan Kr liked this
Vivek Trivedi liked this
Borgomanero liked this
Manish liked this
Nischaiy Chopra liked this
Gordon Lemmon liked this
solo_chikka liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->