SlideShare une entreprise Scribd logo
1  sur  8
OPERATOR
OVERLOADING AND TYPE
CONVERSIONS
IN C++
KEY CONCEPTS
 OVERLOADING
 OPERATOR FUNCTIONS
 OVERLOADING UNARY OPERATORS
 STRING MANIPULATIONS
 BASIC TO CLASS TYPE
 CLASS TO CLASS TYPE
 OPERATOR OVERLOADING
 OVERLOADING BINARY OPERATORS
 USING FRIENDS FOR OVERLOADING
 TYPE CONVERSIONS
 CLASS TO BASIC TYPE
 OVERLOADING RULES
SUMMARY
 Operator overloading is one of the important features of C++ language that
enhances its exhaustibility.
 Using overloading feature we can add two user defined data types such as
objects , with the same syntax , just as basic data types.
 We can overload all the C++ operators except the following:
• Scope resolution operator(::)
• Class member access operator(.,.*)
• Size operator (sizeof)
• Conditional operator(?:)
 Operator overloading is done with the help of special function , called
operator function ,which describes the special task to an operator
SUMMARY CONTD
 There are certain restrictions and limitations in overloading operators.
Operator functions must either be member-functions(nonstatic) or friend
functions. The overloading operator must have at least one operand that is of
user-defined type.
 The compiler does not support automatic type conversions for the user-
defined data types. We can use casting operator to achieve this.
 The casting operator function should satisfy the following conditions:
• It must be a class member
• It must not specify a return type
• It must not have any arguments
KEY TERMS
 ARITHMETIC NOTATION
 BINARY OPERATORS
 CASTING
 CASTING OPERATOR
 CONSTRUCTOR
 CONVERSION FUNCTION
 DESTINATION CLASS
 FRIEND
 FRIEND FUNCTION
 FUNCTIONAL NOTATION
 MANIPULATING STRINGS
KEY TERMS CONTD
 OPERATOR
 OPERATOR FUNCTION
 OPERATOR OVERLOADING
 SCALAR MULTIPLICATION
 SEMANTICS
 SIZEOF
 SOURCE CLASS
 SYNTAX
 TEMPORARY OBJECT
 TYPE CONVERSIONS
 UNARY OPERATORS
REFERENCES
OBJECT ORIENTED PROGRAMMING WITH C++
-E. BALAGURUSAMY
Operator overloading and type conversions

Contenu connexe

Tendances

08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
abhay singh
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 

Tendances (20)

Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
 
polymorphism
polymorphism polymorphism
polymorphism
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Friend function
Friend functionFriend function
Friend function
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Inheritance
InheritanceInheritance
Inheritance
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 

Similaire à Operator overloading and type conversions

Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloading
Princess Sam
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
Princess Sam
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kumar
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kamal Acharya
 

Similaire à Operator overloading and type conversions (20)

OOPS-Seminar.pdf
OOPS-Seminar.pdfOOPS-Seminar.pdf
OOPS-Seminar.pdf
 
NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANI
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloading
 
Operator overloaing
Operator overloaingOperator overloaing
Operator overloaing
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
c++
c++c++
c++
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
9781285852744 ppt ch13
9781285852744 ppt ch139781285852744 ppt ch13
9781285852744 ppt ch13
 
Cpp (C++)
Cpp (C++)Cpp (C++)
Cpp (C++)
 
OPERATING OVERLOADING IN VHDL
OPERATING OVERLOADING IN VHDLOPERATING OVERLOADING IN VHDL
OPERATING OVERLOADING IN VHDL
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Operator Overloading and Scope of Variable
Operator Overloading and Scope of VariableOperator Overloading and Scope of Variable
Operator Overloading and Scope of Variable
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Operator overloading (binary)
Operator overloading (binary)Operator overloading (binary)
Operator overloading (binary)
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
3d7b7 session4 c++
3d7b7 session4 c++3d7b7 session4 c++
3d7b7 session4 c++
 
Oops
OopsOops
Oops
 

Dernier

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Dernier (20)

WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 

Operator overloading and type conversions

  • 2. KEY CONCEPTS  OVERLOADING  OPERATOR FUNCTIONS  OVERLOADING UNARY OPERATORS  STRING MANIPULATIONS  BASIC TO CLASS TYPE  CLASS TO CLASS TYPE  OPERATOR OVERLOADING  OVERLOADING BINARY OPERATORS  USING FRIENDS FOR OVERLOADING  TYPE CONVERSIONS  CLASS TO BASIC TYPE  OVERLOADING RULES
  • 3. SUMMARY  Operator overloading is one of the important features of C++ language that enhances its exhaustibility.  Using overloading feature we can add two user defined data types such as objects , with the same syntax , just as basic data types.  We can overload all the C++ operators except the following: • Scope resolution operator(::) • Class member access operator(.,.*) • Size operator (sizeof) • Conditional operator(?:)  Operator overloading is done with the help of special function , called operator function ,which describes the special task to an operator
  • 4. SUMMARY CONTD  There are certain restrictions and limitations in overloading operators. Operator functions must either be member-functions(nonstatic) or friend functions. The overloading operator must have at least one operand that is of user-defined type.  The compiler does not support automatic type conversions for the user- defined data types. We can use casting operator to achieve this.  The casting operator function should satisfy the following conditions: • It must be a class member • It must not specify a return type • It must not have any arguments
  • 5. KEY TERMS  ARITHMETIC NOTATION  BINARY OPERATORS  CASTING  CASTING OPERATOR  CONSTRUCTOR  CONVERSION FUNCTION  DESTINATION CLASS  FRIEND  FRIEND FUNCTION  FUNCTIONAL NOTATION  MANIPULATING STRINGS
  • 6. KEY TERMS CONTD  OPERATOR  OPERATOR FUNCTION  OPERATOR OVERLOADING  SCALAR MULTIPLICATION  SEMANTICS  SIZEOF  SOURCE CLASS  SYNTAX  TEMPORARY OBJECT  TYPE CONVERSIONS  UNARY OPERATORS
  • 7. REFERENCES OBJECT ORIENTED PROGRAMMING WITH C++ -E. BALAGURUSAMY