
























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
An in-depth exploration of operator overloading and assignment operators in c++. Topics covered include the assignment operator, 'this' pointer, operator overloading using 'this' pointer, conversion functions, and self-assignment. Various examples to illustrate these concepts.
Typology: Slides
1 / 32
This page cannot be seen from the preview
Don't miss anything!

























In Today’s Lecture
Member Wise Assignment
Example class String { char buf [ 100 ] ; public: String ( ) ; ~ String ( ) ; ... } ; Docsity.com
main ( ) { String s1 ( “This is a test” ) ; String s2 ; s2 = s1 ; … … } Example
Example void String :: operator = ( String & s1 ) { delete buf ; buf = new char [ s1.buf + 1 ] ; strcpy ( buf , s1.buf ) ; }
Assignment Operator int i , j , k ; i = 5 ; j = 10 ; k = 15 ; i = j ; k = i ;
k = i = ++ j ;
this pointer
int i ; i = i ; // nothing happens
Example
Example