SlideShare a Scribd company logo
Operator
Overloading
C++
What is an operator?
An operator is a symbol which designed to
operate on data.
They can be a single symbol, di-graphs,
tri-graphs or keywords.
Operators can be classified in different ways.
Based on a number of
arguments
• Unary operators
• Binary operators
• Ternary operators
Based on the location
• prefix operators
• postfix operators
• infix operators
Operator overloading
This is similar to function overloading.
Remember:
Programmers are not allowed to change the
meaning of existing operator but can define on
a new domain.
(eg: cannot force “+” to substract int or float. But can introduce into
“String” which is a new domain)
C++ does not allow programmer to define completely new operator.
(eg: cannot define new operator “$#”)
Overloaded operator is treated as very specific function.
Implement operator
overloading
An operator function can be implemented in two different ways.
• As a member function of a class
(Implicitly assumed that an object of that class is one of the
required operator’s argument)
• As a standalone function
(Function must explicitly specify the types of all arguments)
Operator overloading will not increase either code efficiency or
reliability. But that may improve code readability.
Number of
arguments
Number of arguments are strictly restricted.
Key factors are
• location – (where the operator function is defined)
• operator – (overloading operator)
Keep in mind !
Don’t
• define new operators that is not exist
in C++
• change the priority
• Overload operators that working in
existing data types
Operators
Operator type Operator
Implementation
Return type
As global
function
As a member
function
Arithmetic operator + - * / % Yes Yes Depending on context
Bitwise operator ^| & ~ << >> Yes Yes Depending on context
Assignment operator = No Yes
Reference to an object
or l-value
Relational operator
== != > >= <=
&& ||
Yes Yes Boolean
! Yes Yes -
Compound
assignment operator
+= -= *= %= /= &=
|= ^= >>= <<=
No Yes
Reference to an object
or l-value
Prefix increment and
decrement
++ -- No Yes
Reference to an object
or l-value
Postfix increment and
decrement
++ -- No Yes
Reference to an object
or l-value
Subscript operator [] No Yes
Reference to an object
or l-value
Function invocation
operator
() No Yes Any
& * Yes Yes Any
Non-overloaded
operators
?:
.
::
sizeof
Other overloaded
operators
,
->
new
new[]
delete
delete[]
typename
This is an introduction for operator
overloading. It is better to try these
things and feel free to experiment
with them on your own.
Lahiru Dilshan
Ad

More Related Content

What's hot (20)

Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
Danial Mirza
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
Mahender Boda
 
structure and union
structure and unionstructure and union
structure and union
student
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
Madishetty Prathibha
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
Dr Sukhpal Singh Gill
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Binary operator overloading
Binary operator overloadingBinary operator overloading
Binary operator overloading
BalajiGovindan5
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
Kamal Acharya
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
ThamizhselviKrishnam
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
Md. Ashraful Islam
 
User defined function in c
User defined function in cUser defined function in c
User defined function in c
JeevanandhamSubraman
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
Appili Vamsi Krishna
 
Type conversion
Type  conversionType  conversion
Type conversion
PreethaPreetha5
 

Similar to Operator overloading C++ (20)

Operator overloading (binary)
Operator overloading (binary)Operator overloading (binary)
Operator overloading (binary)
Tirthika Bandi
 
OOPS-Seminar.pdf
OOPS-Seminar.pdfOOPS-Seminar.pdf
OOPS-Seminar.pdf
Rithiga6
 
Cpp (C++)
Cpp (C++)Cpp (C++)
Cpp (C++)
Jay Patel
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Garima Singh Makhija
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading
Charndeep Sekhon
 
c++
c++c++
c++
krishna partiwala
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
sana younas
 
Oops
OopsOops
Oops
ankush_kumar
 
Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloading
Princess Sam
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
ArunaDevi63
 
Operator overloaing
Operator overloaingOperator overloaing
Operator overloaing
zindadili
 
Programming course slides c++ (Prof Mansoor Bhatti)
Programming course slides c++ (Prof Mansoor Bhatti)Programming course slides c++ (Prof Mansoor Bhatti)
Programming course slides c++ (Prof Mansoor Bhatti)
Syed Arslan Rizvi
 
Basics of cpp
Basics of cppBasics of cpp
Basics of cpp
vinay chauhan
 
3d7b7 session4 c++
3d7b7 session4 c++3d7b7 session4 c++
3d7b7 session4 c++
Mukund Trivedi
 
Operator overloadng
Operator overloadngOperator overloadng
Operator overloadng
preethalal
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
Aabha Tiwari
 
Lec 8.pdf a
Lec 8.pdf                                           aLec 8.pdf                                           a
Lec 8.pdf a
aliashraf9689
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kumar
 
OperatorOverloading.ppt
OperatorOverloading.pptOperatorOverloading.ppt
OperatorOverloading.ppt
asadmujtaba001
 
NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANI
Nikul4470
 
Operator overloading (binary)
Operator overloading (binary)Operator overloading (binary)
Operator overloading (binary)
Tirthika Bandi
 
OOPS-Seminar.pdf
OOPS-Seminar.pdfOOPS-Seminar.pdf
OOPS-Seminar.pdf
Rithiga6
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading
Charndeep Sekhon
 
Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloading
Princess Sam
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
ArunaDevi63
 
Operator overloaing
Operator overloaingOperator overloaing
Operator overloaing
zindadili
 
Programming course slides c++ (Prof Mansoor Bhatti)
Programming course slides c++ (Prof Mansoor Bhatti)Programming course slides c++ (Prof Mansoor Bhatti)
Programming course slides c++ (Prof Mansoor Bhatti)
Syed Arslan Rizvi
 
Operator overloadng
Operator overloadngOperator overloadng
Operator overloadng
preethalal
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
Aabha Tiwari
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kumar
 
OperatorOverloading.ppt
OperatorOverloading.pptOperatorOverloading.ppt
OperatorOverloading.ppt
asadmujtaba001
 
NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANI
Nikul4470
 
Ad

More from Lahiru Dilshan (20)

"Capture" in lambda expression.
"Capture" in lambda expression."Capture" in lambda expression.
"Capture" in lambda expression.
Lahiru Dilshan
 
CAD vs CAM vs CAE software.pdf
CAD vs CAM vs CAE software.pdfCAD vs CAM vs CAE software.pdf
CAD vs CAM vs CAE software.pdf
Lahiru Dilshan
 
Degeneracies in 3D modeling.pdf
Degeneracies in 3D modeling.pdfDegeneracies in 3D modeling.pdf
Degeneracies in 3D modeling.pdf
Lahiru Dilshan
 
What does Buffer in C++ means.pdf
What does Buffer in C++ means.pdfWhat does Buffer in C++ means.pdf
What does Buffer in C++ means.pdf
Lahiru Dilshan
 
Open CASCADE for your project.pdf
Open CASCADE for your project.pdfOpen CASCADE for your project.pdf
Open CASCADE for your project.pdf
Lahiru Dilshan
 
Linkage mechanisms - Presentation
Linkage mechanisms - PresentationLinkage mechanisms - Presentation
Linkage mechanisms - Presentation
Lahiru Dilshan
 
Industrial Training Experience
Industrial Training ExperienceIndustrial Training Experience
Industrial Training Experience
Lahiru Dilshan
 
Small scale business analysis
Small scale business analysisSmall scale business analysis
Small scale business analysis
Lahiru Dilshan
 
Computational and experimental investigation of aerodynamics of flapping aero...
Computational and experimental investigation of aerodynamics of flapping aero...Computational and experimental investigation of aerodynamics of flapping aero...
Computational and experimental investigation of aerodynamics of flapping aero...
Lahiru Dilshan
 
Experimental and numerical stress analysis of a rectangular wing structure
Experimental and numerical stress analysis of a rectangular wing structureExperimental and numerical stress analysis of a rectangular wing structure
Experimental and numerical stress analysis of a rectangular wing structure
Lahiru Dilshan
 
Experimental and numerical stress analysis of a rectangular wing structure
Experimental and numerical stress analysis of a rectangular wing structureExperimental and numerical stress analysis of a rectangular wing structure
Experimental and numerical stress analysis of a rectangular wing structure
Lahiru Dilshan
 
Transient three dimensional cfd modelling of ceilng fan
Transient three dimensional cfd modelling of ceilng fanTransient three dimensional cfd modelling of ceilng fan
Transient three dimensional cfd modelling of ceilng fan
Lahiru Dilshan
 
Payload safety and related human factors
Payload safety and related human factorsPayload safety and related human factors
Payload safety and related human factors
Lahiru Dilshan
 
Human factors consideration in emergency evacuation for commercial aircaft
Human factors consideration in emergency evacuation for commercial aircaftHuman factors consideration in emergency evacuation for commercial aircaft
Human factors consideration in emergency evacuation for commercial aircaft
Lahiru Dilshan
 
Human factors in payload safety of fighter aircrafts
Human factors in payload safety of fighter aircraftsHuman factors in payload safety of fighter aircrafts
Human factors in payload safety of fighter aircrafts
Lahiru Dilshan
 
HUMAN FACTOR CONSIDERATIONS IN MILITARY AIRCRAFT MAINTENANCE AND INSPECTIONS
HUMAN FACTOR CONSIDERATIONS IN MILITARY AIRCRAFT MAINTENANCE AND INSPECTIONSHUMAN FACTOR CONSIDERATIONS IN MILITARY AIRCRAFT MAINTENANCE AND INSPECTIONS
HUMAN FACTOR CONSIDERATIONS IN MILITARY AIRCRAFT MAINTENANCE AND INSPECTIONS
Lahiru Dilshan
 
Human factors - Maintenance and inspection
Human factors - Maintenance and inspectionHuman factors - Maintenance and inspection
Human factors - Maintenance and inspection
Lahiru Dilshan
 
Fire safety of passenger aircraft
Fire safety of passenger aircraftFire safety of passenger aircraft
Fire safety of passenger aircraft
Lahiru Dilshan
 
Displays and controls arrangement of military aircraft
Displays and controls arrangement of military aircraftDisplays and controls arrangement of military aircraft
Displays and controls arrangement of military aircraft
Lahiru Dilshan
 
Considerations of human factors on commercial aircraft
Considerations of human factors on commercial aircraftConsiderations of human factors on commercial aircraft
Considerations of human factors on commercial aircraft
Lahiru Dilshan
 
"Capture" in lambda expression.
"Capture" in lambda expression."Capture" in lambda expression.
"Capture" in lambda expression.
Lahiru Dilshan
 
CAD vs CAM vs CAE software.pdf
CAD vs CAM vs CAE software.pdfCAD vs CAM vs CAE software.pdf
CAD vs CAM vs CAE software.pdf
Lahiru Dilshan
 
Degeneracies in 3D modeling.pdf
Degeneracies in 3D modeling.pdfDegeneracies in 3D modeling.pdf
Degeneracies in 3D modeling.pdf
Lahiru Dilshan
 
What does Buffer in C++ means.pdf
What does Buffer in C++ means.pdfWhat does Buffer in C++ means.pdf
What does Buffer in C++ means.pdf
Lahiru Dilshan
 
Open CASCADE for your project.pdf
Open CASCADE for your project.pdfOpen CASCADE for your project.pdf
Open CASCADE for your project.pdf
Lahiru Dilshan
 
Linkage mechanisms - Presentation
Linkage mechanisms - PresentationLinkage mechanisms - Presentation
Linkage mechanisms - Presentation
Lahiru Dilshan
 
Industrial Training Experience
Industrial Training ExperienceIndustrial Training Experience
Industrial Training Experience
Lahiru Dilshan
 
Small scale business analysis
Small scale business analysisSmall scale business analysis
Small scale business analysis
Lahiru Dilshan
 
Computational and experimental investigation of aerodynamics of flapping aero...
Computational and experimental investigation of aerodynamics of flapping aero...Computational and experimental investigation of aerodynamics of flapping aero...
Computational and experimental investigation of aerodynamics of flapping aero...
Lahiru Dilshan
 
Experimental and numerical stress analysis of a rectangular wing structure
Experimental and numerical stress analysis of a rectangular wing structureExperimental and numerical stress analysis of a rectangular wing structure
Experimental and numerical stress analysis of a rectangular wing structure
Lahiru Dilshan
 
Experimental and numerical stress analysis of a rectangular wing structure
Experimental and numerical stress analysis of a rectangular wing structureExperimental and numerical stress analysis of a rectangular wing structure
Experimental and numerical stress analysis of a rectangular wing structure
Lahiru Dilshan
 
Transient three dimensional cfd modelling of ceilng fan
Transient three dimensional cfd modelling of ceilng fanTransient three dimensional cfd modelling of ceilng fan
Transient three dimensional cfd modelling of ceilng fan
Lahiru Dilshan
 
Payload safety and related human factors
Payload safety and related human factorsPayload safety and related human factors
Payload safety and related human factors
Lahiru Dilshan
 
Human factors consideration in emergency evacuation for commercial aircaft
Human factors consideration in emergency evacuation for commercial aircaftHuman factors consideration in emergency evacuation for commercial aircaft
Human factors consideration in emergency evacuation for commercial aircaft
Lahiru Dilshan
 
Human factors in payload safety of fighter aircrafts
Human factors in payload safety of fighter aircraftsHuman factors in payload safety of fighter aircrafts
Human factors in payload safety of fighter aircrafts
Lahiru Dilshan
 
HUMAN FACTOR CONSIDERATIONS IN MILITARY AIRCRAFT MAINTENANCE AND INSPECTIONS
HUMAN FACTOR CONSIDERATIONS IN MILITARY AIRCRAFT MAINTENANCE AND INSPECTIONSHUMAN FACTOR CONSIDERATIONS IN MILITARY AIRCRAFT MAINTENANCE AND INSPECTIONS
HUMAN FACTOR CONSIDERATIONS IN MILITARY AIRCRAFT MAINTENANCE AND INSPECTIONS
Lahiru Dilshan
 
Human factors - Maintenance and inspection
Human factors - Maintenance and inspectionHuman factors - Maintenance and inspection
Human factors - Maintenance and inspection
Lahiru Dilshan
 
Fire safety of passenger aircraft
Fire safety of passenger aircraftFire safety of passenger aircraft
Fire safety of passenger aircraft
Lahiru Dilshan
 
Displays and controls arrangement of military aircraft
Displays and controls arrangement of military aircraftDisplays and controls arrangement of military aircraft
Displays and controls arrangement of military aircraft
Lahiru Dilshan
 
Considerations of human factors on commercial aircraft
Considerations of human factors on commercial aircraftConsiderations of human factors on commercial aircraft
Considerations of human factors on commercial aircraft
Lahiru Dilshan
 
Ad

Recently uploaded (20)

Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
A Comprehensive Guide to CRM Software Benefits for Every Business Stage
A Comprehensive Guide to CRM Software Benefits for Every Business StageA Comprehensive Guide to CRM Software Benefits for Every Business Stage
A Comprehensive Guide to CRM Software Benefits for Every Business Stage
SynapseIndia
 
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdfTop Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
evrigsolution
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Adobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREEAdobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREE
zafranwaqar90
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
wAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptxwAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptx
SimonedeGijt
 
Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
A Comprehensive Guide to CRM Software Benefits for Every Business Stage
A Comprehensive Guide to CRM Software Benefits for Every Business StageA Comprehensive Guide to CRM Software Benefits for Every Business Stage
A Comprehensive Guide to CRM Software Benefits for Every Business Stage
SynapseIndia
 
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdfTop Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
evrigsolution
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Adobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREEAdobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREE
zafranwaqar90
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
wAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptxwAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptx
SimonedeGijt
 
Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 

Operator overloading C++

  • 2. What is an operator? An operator is a symbol which designed to operate on data. They can be a single symbol, di-graphs, tri-graphs or keywords. Operators can be classified in different ways. Based on a number of arguments • Unary operators • Binary operators • Ternary operators Based on the location • prefix operators • postfix operators • infix operators
  • 3. Operator overloading This is similar to function overloading. Remember: Programmers are not allowed to change the meaning of existing operator but can define on a new domain. (eg: cannot force “+” to substract int or float. But can introduce into “String” which is a new domain) C++ does not allow programmer to define completely new operator. (eg: cannot define new operator “$#”) Overloaded operator is treated as very specific function.
  • 4. Implement operator overloading An operator function can be implemented in two different ways. • As a member function of a class (Implicitly assumed that an object of that class is one of the required operator’s argument) • As a standalone function (Function must explicitly specify the types of all arguments) Operator overloading will not increase either code efficiency or reliability. But that may improve code readability.
  • 5. Number of arguments Number of arguments are strictly restricted. Key factors are • location – (where the operator function is defined) • operator – (overloading operator)
  • 6. Keep in mind ! Don’t • define new operators that is not exist in C++ • change the priority • Overload operators that working in existing data types
  • 7. Operators Operator type Operator Implementation Return type As global function As a member function Arithmetic operator + - * / % Yes Yes Depending on context Bitwise operator ^| & ~ << >> Yes Yes Depending on context Assignment operator = No Yes Reference to an object or l-value Relational operator == != > >= <= && || Yes Yes Boolean ! Yes Yes - Compound assignment operator += -= *= %= /= &= |= ^= >>= <<= No Yes Reference to an object or l-value Prefix increment and decrement ++ -- No Yes Reference to an object or l-value Postfix increment and decrement ++ -- No Yes Reference to an object or l-value Subscript operator [] No Yes Reference to an object or l-value Function invocation operator () No Yes Any & * Yes Yes Any
  • 9. This is an introduction for operator overloading. It is better to try these things and feel free to experiment with them on your own. Lahiru Dilshan
  翻译: