SlideShare a Scribd company logo
Prepared by
Mohammed Sikander
Technical Lead
Cranes Software
Mohammed.sikander@cranessoftware.com
Operator Overloading
1. *
2. ->
3. .
4. ( )
5. &&
Mohammed Sikander cranesvarsity.com
 ++
 =
 [ ]
 <<
Mohammed Sikander cranesvarsity.com
class Distance{
private : int feet , inch;
public : Distance(int ft = 0 , int in = 0)
{
feet = ft ; inch = in;
}
Distance operator ++( )
{
…..
}
};
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1(2 , 6);
2. ++d1;
3. d1++;
}
Is it post Increment / pre Increment
class Distance{
private : int feet , inch;
public : Distance(int ft = 0 , int in = 0){
feet = ft ; inch = in;
}
Distance operator ++(int )
{
…..
}
};
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1(2 , 6);
2. ++d1;
3. d1++;
}
Is it post Increment / pre
Increment
class Distance{
private : int feet , inch;
public :
Distance(int ft = 0 , int in = 0)
{
feet = ft ; inch = in;
}
void operator ++( )
{
++feet;
}
void print( )
{
cout <<feet<<“’”<<inch<<“”” <<endl;
}
};
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1(2 , 6)
2. Distance d2;
3. ++d1;
4. d2 = ++d1;
5. d1.print( );
6. d2.print( );
}
class Distance{
private : int feet , inch;
public : Distance(int ft = 0 , int in = 0)
{
feet = ft ; inch = in;
}
Distance operator ++( )
{
++feet;
return *this;
}
void print( )
{
cout <<feet<<“’”<<inch<<“”” <<endl;
}
};
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1(2 , 6)
2. Distance d2;
3. d2 = ++d1;
4. d1.print( );
5. d2.print( );
}
class Distance{
private : int feet , inch;
public : Distance(int ft = 0 , int in = 0)
{
feet = ft ; inch = in;
}
Distance operator ++( int )
{
feet++;
return *this;
}
void print( )
{
cout <<feet<<“’”<<inch<<“”” <<endl;
}
};
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1(2 , 6) ,d2;
2. d2 = d1++;
3. d1.print( );
4. d2.print( );
}
class Distance{
private : int feet , inch;
public : Distance(int ft = 0 , int in = 0)
{
feet = ft ; inch = in;
}
Distance operator ++(int )
{
Distance temp = *this;
feet++;
return temp;
}
void print( )
{
cout <<feet<<“’”<<inch<<“”” <<endl;
}
};
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1(2 , 6) ,d2;
2. d2 = d1++;
3. d1.print( );
4. d2.print( );
}
class Distance{
private : int feet , inch;
public : Distance(int ft = 0 , int in = 0)
{
feet = ft ; inch = in;
}
Distance operator ++( )
{ cout <<“Pre Increment n”;
……
}
Distance operator ++(int )
{ cout <<“Post Increment n”;
……
}
};
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1(2 , 6) ,d2;
2. d2 = ++d1++;
}
class Distance{
private : int feet , inch;
public : Distance(int ft = 0 , int in = 0)
{
feet = ft ; inch = in;
}
Distance operator ++( ){
cout <<“this = “ << this << endl;
feet++;
return *this;
}
void print( )
{
cout <<feet<<“’”<<inch<<“”” <<endl;
}
};
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1(2 , 6);
2. Distance d2;
3. cout <<&d1 << endl;
4. d2 = ++++d1;
5. d1.print( );
6. d2.print( );
}
Change the return type to
Distance & operator ++( )
class Distance{
private : int feet , inch;
public : Distance(int ft = 0 , int in = 0){
feet = ft ; inch = in;
}
Distance operator +(const Distance &d)
{
………
}
};
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1 = 5;
2. Distance d2(2 , 6);
3. Distance d3;
4. d3 = d1 + 5;
5. d3 = 5 + d2;
}
class Distance{
private : int feet , inch;
public : Distance(int ft = 0 , int in = 0)
{
feet = ft ; inch = in;
}
};
Distance operator +(const Distance &d1,const Distance &d2)
{
Distance temp;
return temp;
}
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1 = 5;
2. Distance d2(2 , 6);
3. Distance d3;
4. d3 = d1 + 5;
5. d3 = 5 + d2;
}
class Distance{
private : int feet , inch;
public : Distance(int ft = 0 , int in = 0){
feet = ft ; inch = in;
}
};
Distance operator +(const Distance &d1,const Distance &d2)
{
Distance temp(d1.feet + d2.feet , d1.inch +d2.inch);
if(temp.inch >= 12)
{
temp.inch -= 12;
temp.feet++;
}
return temp;
}
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1 = 5;
2. Distance d2(2 , 6);
3. Distance d3;
4. d3 = d1 + 5;
5. d3 = 5 + d2;
}
class Distance{
private : int feet , inch;
public : Distance(int ft = 0 , int in = 0){
feet = ft ; inch = in;
}
friend Distance operator +(const Distance &d1,const Distance &d2);
};
Distance operator +(const Distance &d1,const Distance &d2)
{
Distance temp(d1.feet + d2.feet , d1.inch +d2.inch);
if(temp.inch >= 12)
{
temp.inch -= 12;
temp.feet++;
}
return temp;
}
Mohammed Sikander cranesvarsity.com
int main( )
{
1. Distance d1 = 5;
2. Distance d2(2 , 6);
3. Distance d3;
4. d3 = d1 + 5;
5. d3 = 5 + d2;
}

More Related Content

PDF
Static and const members
PDF
Implementing stack
PDF
Container adapters
PDF
Stl algorithm-Basic types
PDF
Inheritance and polymorphism
PDF
C++ Question on References and Function Overloading
PDF
Polymorphism
PPTX
Function basics
Static and const members
Implementing stack
Container adapters
Stl algorithm-Basic types
Inheritance and polymorphism
C++ Question on References and Function Overloading
Polymorphism
Function basics

What's hot (20)

PDF
Implementing string
PDF
Understanding storage class using nm
PDF
C++ Programming - 1st Study
PPT
Cquestions
PPT
C questions
PDF
C++ Programming - 11th Study
PDF
C++ Programming - 4th Study
PDF
C++ TUTORIAL 5
PDF
C++ TUTORIAL 2
PDF
C++ Programming - 2nd Study
PDF
C++ TUTORIAL 1
DOCX
Quiz 10 cp_sol
PDF
C++ Programming - 14th Study
PDF
Data Structure - 2nd Study
PDF
C++ TUTORIAL 10
PDF
C++ TUTORIAL 3
PPTX
PDF
C++ TUTORIAL 8
PDF
C++ Programming - 3rd Study
PPTX
C sharp 8
Implementing string
Understanding storage class using nm
C++ Programming - 1st Study
Cquestions
C questions
C++ Programming - 11th Study
C++ Programming - 4th Study
C++ TUTORIAL 5
C++ TUTORIAL 2
C++ Programming - 2nd Study
C++ TUTORIAL 1
Quiz 10 cp_sol
C++ Programming - 14th Study
Data Structure - 2nd Study
C++ TUTORIAL 10
C++ TUTORIAL 3
C++ TUTORIAL 8
C++ Programming - 3rd Study
C sharp 8
Ad

Viewers also liked (13)

DOCX
Colleen Kolakowski Resume 12-27-2016
PPTX
Redes sociales
PPTX
Pointer level 2
PPT
3 palestra sergio 2012
PDF
New definition for being fit - Just Dance
PDF
Resti fiks fdf
DOCX
Standar asuhan keperawatan klien dengan halusinasi
PDF
Kuukausittainen matkailutilasto Etelä-Savo syyskuu 2015
PDF
Data structures in C Singlly Linked List Concept
PDF
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU HAMIL PADA NY “S” DENGAN ...
PPTX
Successful Tourism Strategic Plans for Destinations - Dr. Harsh Varma
DOCX
Core java notes with examples
Colleen Kolakowski Resume 12-27-2016
Redes sociales
Pointer level 2
3 palestra sergio 2012
New definition for being fit - Just Dance
Resti fiks fdf
Standar asuhan keperawatan klien dengan halusinasi
Kuukausittainen matkailutilasto Etelä-Savo syyskuu 2015
Data structures in C Singlly Linked List Concept
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU HAMIL PADA NY “S” DENGAN ...
Successful Tourism Strategic Plans for Destinations - Dr. Harsh Varma
Core java notes with examples
Ad

Similar to Operator overloading (20)

PPTX
operator overloading
PDF
Oop assignment 02
PDF
Object Oriented Programming (OOP) using C++ - Lecture 2
PPTX
3. Polymorphism.pptx
PPTX
Oop ( operator overloading)
PPTX
Object orinted programming lecture| Overlaoded Functions
PDF
Object Oriented Programming (OOP) using C++ - Lecture 3
PPTX
OOP.pptx
PPTX
New presentation oop
PPT
Overloading
PDF
Object Oriented Programming using C++ - Part 3
PDF
Basics _of_Operator Overloading_Somesh_Kumar_SSTC
PDF
Object Oriented Programming notes provided
PDF
C++ manual Report Full
DOCX
Make two classes called Points and Lines- Class points should have the.docx
PPTX
Object Oriented Programming using C++: Ch09 Inheritance.pptx
PPTX
Oop presentation
PDF
C++ normal assignments by maharshi_jd.pdf
PPTX
OOPS Basics With Example
operator overloading
Oop assignment 02
Object Oriented Programming (OOP) using C++ - Lecture 2
3. Polymorphism.pptx
Oop ( operator overloading)
Object orinted programming lecture| Overlaoded Functions
Object Oriented Programming (OOP) using C++ - Lecture 3
OOP.pptx
New presentation oop
Overloading
Object Oriented Programming using C++ - Part 3
Basics _of_Operator Overloading_Somesh_Kumar_SSTC
Object Oriented Programming notes provided
C++ manual Report Full
Make two classes called Points and Lines- Class points should have the.docx
Object Oriented Programming using C++: Ch09 Inheritance.pptx
Oop presentation
C++ normal assignments by maharshi_jd.pdf
OOPS Basics With Example

Recently uploaded (20)

PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
medical staffing services at VALiNTRY
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
history of c programming in notes for students .pptx
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
How Creative Agencies Leverage Project Management Software.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
medical staffing services at VALiNTRY
Wondershare Filmora 15 Crack With Activation Key [2025
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Reimagine Home Health with the Power of Agentic AI​
Understanding Forklifts - TECH EHS Solution
history of c programming in notes for students .pptx
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Odoo POS Development Services by CandidRoot Solutions
Upgrade and Innovation Strategies for SAP ERP Customers
wealthsignaloriginal-com-DS-text-... (1).pdf
Design an Analysis of Algorithms II-SECS-1021-03
Design an Analysis of Algorithms I-SECS-1021-03
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

Operator overloading

  • 1. Prepared by Mohammed Sikander Technical Lead Cranes Software Mohammed.sikander@cranessoftware.com Operator Overloading
  • 2. 1. * 2. -> 3. . 4. ( ) 5. && Mohammed Sikander cranesvarsity.com
  • 3.  ++  =  [ ]  << Mohammed Sikander cranesvarsity.com
  • 4. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0) { feet = ft ; inch = in; } Distance operator ++( ) { ….. } }; Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1(2 , 6); 2. ++d1; 3. d1++; } Is it post Increment / pre Increment
  • 5. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0){ feet = ft ; inch = in; } Distance operator ++(int ) { ….. } }; Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1(2 , 6); 2. ++d1; 3. d1++; } Is it post Increment / pre Increment
  • 6. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0) { feet = ft ; inch = in; } void operator ++( ) { ++feet; } void print( ) { cout <<feet<<“’”<<inch<<“”” <<endl; } }; Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1(2 , 6) 2. Distance d2; 3. ++d1; 4. d2 = ++d1; 5. d1.print( ); 6. d2.print( ); }
  • 7. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0) { feet = ft ; inch = in; } Distance operator ++( ) { ++feet; return *this; } void print( ) { cout <<feet<<“’”<<inch<<“”” <<endl; } }; Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1(2 , 6) 2. Distance d2; 3. d2 = ++d1; 4. d1.print( ); 5. d2.print( ); }
  • 8. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0) { feet = ft ; inch = in; } Distance operator ++( int ) { feet++; return *this; } void print( ) { cout <<feet<<“’”<<inch<<“”” <<endl; } }; Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1(2 , 6) ,d2; 2. d2 = d1++; 3. d1.print( ); 4. d2.print( ); }
  • 9. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0) { feet = ft ; inch = in; } Distance operator ++(int ) { Distance temp = *this; feet++; return temp; } void print( ) { cout <<feet<<“’”<<inch<<“”” <<endl; } }; Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1(2 , 6) ,d2; 2. d2 = d1++; 3. d1.print( ); 4. d2.print( ); }
  • 10. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0) { feet = ft ; inch = in; } Distance operator ++( ) { cout <<“Pre Increment n”; …… } Distance operator ++(int ) { cout <<“Post Increment n”; …… } }; Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1(2 , 6) ,d2; 2. d2 = ++d1++; }
  • 11. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0) { feet = ft ; inch = in; } Distance operator ++( ){ cout <<“this = “ << this << endl; feet++; return *this; } void print( ) { cout <<feet<<“’”<<inch<<“”” <<endl; } }; Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1(2 , 6); 2. Distance d2; 3. cout <<&d1 << endl; 4. d2 = ++++d1; 5. d1.print( ); 6. d2.print( ); } Change the return type to Distance & operator ++( )
  • 12. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0){ feet = ft ; inch = in; } Distance operator +(const Distance &d) { ……… } }; Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1 = 5; 2. Distance d2(2 , 6); 3. Distance d3; 4. d3 = d1 + 5; 5. d3 = 5 + d2; }
  • 13. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0) { feet = ft ; inch = in; } }; Distance operator +(const Distance &d1,const Distance &d2) { Distance temp; return temp; } Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1 = 5; 2. Distance d2(2 , 6); 3. Distance d3; 4. d3 = d1 + 5; 5. d3 = 5 + d2; }
  • 14. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0){ feet = ft ; inch = in; } }; Distance operator +(const Distance &d1,const Distance &d2) { Distance temp(d1.feet + d2.feet , d1.inch +d2.inch); if(temp.inch >= 12) { temp.inch -= 12; temp.feet++; } return temp; } Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1 = 5; 2. Distance d2(2 , 6); 3. Distance d3; 4. d3 = d1 + 5; 5. d3 = 5 + d2; }
  • 15. class Distance{ private : int feet , inch; public : Distance(int ft = 0 , int in = 0){ feet = ft ; inch = in; } friend Distance operator +(const Distance &d1,const Distance &d2); }; Distance operator +(const Distance &d1,const Distance &d2) { Distance temp(d1.feet + d2.feet , d1.inch +d2.inch); if(temp.inch >= 12) { temp.inch -= 12; temp.feet++; } return temp; } Mohammed Sikander cranesvarsity.com int main( ) { 1. Distance d1 = 5; 2. Distance d2(2 , 6); 3. Distance d3; 4. d3 = d1 + 5; 5. d3 = 5 + d2; }