


























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Syntax for overloading operators, Overload operators, Complex Number, Complete list of C operators, Friend Function, User Defined Data types, String are the key points of this lecture.
Typology: Slides
1 / 34
This page cannot be seen from the preview
Don't miss anything!



























Lecture 31
Operator
Overloading
Complex
Number
complex c1 , c2 , x ;
x = cadd ( c1 , c2 ) ;
Operators The complete list of C++ operators that are overloaded is as follows
= && | | ++ - - -> * , -> [ ] ( ) new new[ ] delete delete [ ] Docsity.com
Example
Return_type operator + (Argument_List)
{
// Body of function
}
a * b + c ;
Example
class Complex
{
private : double real ; double imag ; public : // member function
} Docsity.com
Example
Complex c1 , c2 ;
c1 = c2 ;
Is equivalent to
c1.real = c2.real ;
c1.imag = c2.imag ;
Complex Complex :: operator + ( Complex c )
{
Complex temp ; temp.real = real + c.real ; temp.imag = imag + c.imag ; return temp ;
}
Example
Complex x , y , z ;
z = x + y ;
z = x + y ;
z = x + d ;