SlideShare a Scribd company logo
1 of 11
Operator Overloading and
Type Conversion
Chapter – 10
10.1 Introduction
 Operator Overloading is similar to that of Function Overloading.
 It is a type of Polymorphism
 Polymorphism allows to permit multiple definitions for functions and
operators
 Operator Overloading helps the programmer to use the operators with
objects of classes.
 Eg. Book
10.2 The Keyword Operator
10.3 Overloading Unary Operators
 Overloading of explicit argument to an operator function is
called unary operator overloading.
 Operators ++ , -- and – are unary operator.
 Unary operator ++ and – can be used as prefix or suffix with
functions
 Eg. Book
10.7 Overloading with friend Function
 friend functions are more useful in operator overloading.
 Difference b/n member function and friend function is the member function takes
argument explicitly.
 friend function needs parameters to be explicitly passed
 Syntax:
10.9 Type Conversion
Three possibilities of Data Conversions are
Conversion from Basic Data type to User-defined data type(class
type)
Conversion from class type to basic data type
Conversion from one class type to another class type
10.9.1Conversion from Basic to class type
It is automatically done by the compiler with the help of
built-in routines or by applying type casting.
Here , left-hand operand of = sign is always class type and
right-hand sign operand is always basic type
Eg. Book
10.9.2 Conversion from Class type to Basic Data Type
 Compiler does not know about user defined data type built using
classes.
 Programmer needs explicitly tell the compiler about the conversion
from class to basic type
 Such type of conversion is known as Overloading of type cast
operators
 Here left-hand operand is always basic data type
 Right-hand operand is always of class type
10.9.2 Conversion from Class type to Basic Data Type
 During conversion , statement should satisfy following conditions
:
 The conversion function should not have any argument
 Do not mention return type
 It should be a class member function
 Eg. Book
10.9.3 Conversion from One Class type to Another
Class Type
When an object of one class is assigned to object
of another class, important to give clear
instructions to compiler about how to make
conversion b/n 2 user-defined data type.
10.10 Rules for Overloading Operators
When an operator is overloaded ,its properties
like syntax , precedence and associatively
remain constant

More Related Content

What's hot

Java Chapter 04 - Writing Classes: part 4
Java Chapter 04 - Writing Classes: part 4Java Chapter 04 - Writing Classes: part 4
Java Chapter 04 - Writing Classes: part 4
DanWooster1
 
Java Chapter 04 - Writing Classes: part 2
Java Chapter 04 - Writing Classes: part 2Java Chapter 04 - Writing Classes: part 2
Java Chapter 04 - Writing Classes: part 2
DanWooster1
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
Jeevan Raj
 

What's hot (20)

Mule Expression language
Mule Expression languageMule Expression language
Mule Expression language
 
Function
FunctionFunction
Function
 
Java Chapter 04 - Writing Classes: part 4
Java Chapter 04 - Writing Classes: part 4Java Chapter 04 - Writing Classes: part 4
Java Chapter 04 - Writing Classes: part 4
 
Mule mel 1
Mule mel 1Mule mel 1
Mule mel 1
 
Introduction to programming using mat ab
Introduction to programming using mat abIntroduction to programming using mat ab
Introduction to programming using mat ab
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Mule data weave_2
Mule data weave_2Mule data weave_2
Mule data weave_2
 
Java Chapter 04 - Writing Classes: part 2
Java Chapter 04 - Writing Classes: part 2Java Chapter 04 - Writing Classes: part 2
Java Chapter 04 - Writing Classes: part 2
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
 
Operator Overloading & Function Overloading
Operator Overloading & Function OverloadingOperator Overloading & Function Overloading
Operator Overloading & Function Overloading
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
 
Recursion
RecursionRecursion
Recursion
 
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
 
Mule expression
Mule expressionMule expression
Mule expression
 
Programming Sessions KU Leuven - Session 02
Programming Sessions KU Leuven - Session 02Programming Sessions KU Leuven - Session 02
Programming Sessions KU Leuven - Session 02
 
[論文紹介] Deep contextualized word representations
[論文紹介] Deep contextualized word representations[論文紹介] Deep contextualized word representations
[論文紹介] Deep contextualized word representations
 
Immutable data structures - A Primer
Immutable data structures - A PrimerImmutable data structures - A Primer
Immutable data structures - A Primer
 
user defined functions in R
user defined functions in Ruser defined functions in R
user defined functions in R
 
implementing oop_concept
 implementing oop_concept implementing oop_concept
implementing oop_concept
 

Similar to Operator Overloading

Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
nirajmandaliya
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 

Similar to Operator Overloading (20)

NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANI
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Ch-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdfCh-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdf
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Ch9 Functions
Ch9 FunctionsCh9 Functions
Ch9 Functions
 
Operator_Overloaing_Type_Conversion_OOPC(C++)
Operator_Overloaing_Type_Conversion_OOPC(C++)Operator_Overloaing_Type_Conversion_OOPC(C++)
Operator_Overloaing_Type_Conversion_OOPC(C++)
 
Operator overloaing
Operator overloaingOperator overloaing
Operator overloaing
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
Functions and Arguments in Python
Functions and Arguments in PythonFunctions and Arguments in Python
Functions and Arguments in Python
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
 
overloading in C++
overloading in C++overloading in C++
overloading in C++
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
 
Savitch ch 11
Savitch ch 11Savitch ch 11
Savitch ch 11
 
C functions
C functionsC functions
C functions
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
OOP_UnitIII.pdf
OOP_UnitIII.pdfOOP_UnitIII.pdf
OOP_UnitIII.pdf
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
 
Type conversions
Type conversionsType conversions
Type conversions
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Recently uploaded (20)

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 

Operator Overloading

  • 1. Operator Overloading and Type Conversion Chapter – 10
  • 2. 10.1 Introduction  Operator Overloading is similar to that of Function Overloading.  It is a type of Polymorphism  Polymorphism allows to permit multiple definitions for functions and operators  Operator Overloading helps the programmer to use the operators with objects of classes.  Eg. Book
  • 3. 10.2 The Keyword Operator
  • 4. 10.3 Overloading Unary Operators  Overloading of explicit argument to an operator function is called unary operator overloading.  Operators ++ , -- and – are unary operator.  Unary operator ++ and – can be used as prefix or suffix with functions  Eg. Book
  • 5. 10.7 Overloading with friend Function  friend functions are more useful in operator overloading.  Difference b/n member function and friend function is the member function takes argument explicitly.  friend function needs parameters to be explicitly passed  Syntax:
  • 6. 10.9 Type Conversion Three possibilities of Data Conversions are Conversion from Basic Data type to User-defined data type(class type) Conversion from class type to basic data type Conversion from one class type to another class type
  • 7. 10.9.1Conversion from Basic to class type It is automatically done by the compiler with the help of built-in routines or by applying type casting. Here , left-hand operand of = sign is always class type and right-hand sign operand is always basic type Eg. Book
  • 8. 10.9.2 Conversion from Class type to Basic Data Type  Compiler does not know about user defined data type built using classes.  Programmer needs explicitly tell the compiler about the conversion from class to basic type  Such type of conversion is known as Overloading of type cast operators  Here left-hand operand is always basic data type  Right-hand operand is always of class type
  • 9. 10.9.2 Conversion from Class type to Basic Data Type  During conversion , statement should satisfy following conditions :  The conversion function should not have any argument  Do not mention return type  It should be a class member function  Eg. Book
  • 10. 10.9.3 Conversion from One Class type to Another Class Type When an object of one class is assigned to object of another class, important to give clear instructions to compiler about how to make conversion b/n 2 user-defined data type.
  • 11. 10.10 Rules for Overloading Operators When an operator is overloaded ,its properties like syntax , precedence and associatively remain constant