SlideShare a Scribd company logo
5
Most read
6
Most read
8
Most read
G.BALAJI MCA, M.Tech.,
Assistant Professor of Computer Science
Vivekananda College, Madurai
Operator Overloading:
 Operator – It is a symbol that indicates an operation.
Arithmetic operators are + (add two numbers), - (subtract two
numbers), * ( Multiply two numbers), / ( Divide between two
numbers).
 At now, we will take an Addition ‘+’ Sign, its use of ‘+’ sign
is
5+5=10
2.5+2.5=5
 Operator Overloading means multiple functions or multiple
jobs. In operator overloading the ‘+’ sign use of add the two
objects.
 One of C++’s great features is its extensibility, Operator
Overloading is major functionality related to extensibility.
 In C++, most of operators can be overloaded so that they can
perform special operations relative to the classes you create.
 For Example, ‘+’ operator can be overloaded to perform an
operation of string concatenation along with its pre-defined
job of adding two numeric values.
 When an operator is overloaded, none of its original meaning
will be lost.
 After overloading the appropriate operators, you can use
C++’s built in data types.
 Unary Operator
- Operators attached to a single operand.
(-a, +a, --a, ++a, a--, a++)
 Binary Operator
- Operators attached to two operand.
(a-b, a+b, a*b, a/b, a%b, a>b, a<b )
return-type class-name:: operator op(arg-list)
{
function body
}
EXPLANATION
 return type – It is the type of value returned by the specified
operation.
 op - It is the operator being overloaded. It may be unary or
binary operator. It is preceded by the keyword operator.
 operator op - It is the function name, Where operator is a
keyword.
 Overloaded operator functions can be invoked by expressions
such as:
For unary operator: op x or op y
eg: +a, -a, ++b, b--.
For binary operator: x op y
eg: a+b, a*b, a<b.
 Only existing operators can be overloaded. New operators
cannot be created.
 The overloaded operator must have at least one operand that is
of user-defined type.
 We cannot change the basic meaning of an operator.
 Overloaded operators follow the syntax rules of the original
operators.
 The following operators that cannot be overloaded.
Size of Size of operator
. Membership operator
.* Pointer-to-member operator
:: Scope resolution operator
?; Conditional Operator

More Related Content

PPTX
Types of Constructor in C++
PPTX
Object oriented programming
PPTX
Member Function in C++
PPTX
Abstract class in c++
PDF
Constructor and Destructor
PPTX
Constructor and Destructors in C++
PPTX
virtual function
PPTX
classes and objects in C++
Types of Constructor in C++
Object oriented programming
Member Function in C++
Abstract class in c++
Constructor and Destructor
Constructor and Destructors in C++
virtual function
classes and objects in C++

What's hot (20)

PPT
Basic concepts of object oriented programming
PPTX
Data types in c++
PPTX
Functions in c++
PPT
friend function(c++)
PPTX
Templates in c++
PPT
Files in c++ ppt
PPTX
Control structures in c++
PPSX
Files in c++
PPTX
Exception handling c++
PPTX
Chapter 07 inheritance
PPTX
Method overloading
PPTX
Abstract Data Types
PPT
Function overloading(c++)
PDF
Operator overloading C++
PPTX
Function overloading and overriding
PPTX
Constructor and destructor
PPT
ABSTRACT CLASSES AND INTERFACES.ppt
PPTX
Inheritance in c++
PPT
Abstract class
PPTX
Interface in java
Basic concepts of object oriented programming
Data types in c++
Functions in c++
friend function(c++)
Templates in c++
Files in c++ ppt
Control structures in c++
Files in c++
Exception handling c++
Chapter 07 inheritance
Method overloading
Abstract Data Types
Function overloading(c++)
Operator overloading C++
Function overloading and overriding
Constructor and destructor
ABSTRACT CLASSES AND INTERFACES.ppt
Inheritance in c++
Abstract class
Interface in java
Ad

Similar to Operator overloading in C++ (20)

PPT
Unary operator overloading
PPT
Binary operator overloading
PPTX
PPTX
Operator overloading
PPT
Lec 26.27-operator overloading
PPTX
Operator overloading
PPT
08 c++ Operator Overloading.ppt
PPT
08 c-operator-overloadingppt2563
PPTX
Operator overloading
DOCX
Operator oveerloading
PPT
Lec 28 - operator overloading
PPTX
Operator overloaing
PPTX
Presentation on overloading
PPTX
Increment and Decrement operators in C++
PPT
Polymorphism and function overloading_new.ppt
PDF
Ch-4-Operator Overloading.pdf
PPTX
Operator overloading
PPTX
Cpp (C++)
PPTX
Operator Overloading
PDF
overloading in C++
Unary operator overloading
Binary operator overloading
Operator overloading
Lec 26.27-operator overloading
Operator overloading
08 c++ Operator Overloading.ppt
08 c-operator-overloadingppt2563
Operator overloading
Operator oveerloading
Lec 28 - operator overloading
Operator overloaing
Presentation on overloading
Increment and Decrement operators in C++
Polymorphism and function overloading_new.ppt
Ch-4-Operator Overloading.pdf
Operator overloading
Cpp (C++)
Operator Overloading
overloading in C++
Ad

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
master seminar digital applications in india
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Pre independence Education in Inndia.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Cell Types and Its function , kingdom of life
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
01-Introduction-to-Information-Management.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Institutional Correction lecture only . . .
102 student loan defaulters named and shamed – Is someone you know on the list?
master seminar digital applications in india
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPH.pptx obstetrics and gynecology in nursing
Pre independence Education in Inndia.pdf
Sports Quiz easy sports quiz sports quiz
2.FourierTransform-ShortQuestionswithAnswers.pdf
GDM (1) (1).pptx small presentation for students
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Cell Types and Its function , kingdom of life
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Computing-Curriculum for Schools in Ghana
01-Introduction-to-Information-Management.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Institutional Correction lecture only . . .

Operator overloading in C++

  • 1. G.BALAJI MCA, M.Tech., Assistant Professor of Computer Science Vivekananda College, Madurai
  • 2. Operator Overloading:  Operator – It is a symbol that indicates an operation. Arithmetic operators are + (add two numbers), - (subtract two numbers), * ( Multiply two numbers), / ( Divide between two numbers).  At now, we will take an Addition ‘+’ Sign, its use of ‘+’ sign is 5+5=10 2.5+2.5=5
  • 3.  Operator Overloading means multiple functions or multiple jobs. In operator overloading the ‘+’ sign use of add the two objects.  One of C++’s great features is its extensibility, Operator Overloading is major functionality related to extensibility.  In C++, most of operators can be overloaded so that they can perform special operations relative to the classes you create.
  • 4.  For Example, ‘+’ operator can be overloaded to perform an operation of string concatenation along with its pre-defined job of adding two numeric values.  When an operator is overloaded, none of its original meaning will be lost.  After overloading the appropriate operators, you can use C++’s built in data types.
  • 5.  Unary Operator - Operators attached to a single operand. (-a, +a, --a, ++a, a--, a++)  Binary Operator - Operators attached to two operand. (a-b, a+b, a*b, a/b, a%b, a>b, a<b )
  • 6. return-type class-name:: operator op(arg-list) { function body } EXPLANATION  return type – It is the type of value returned by the specified operation.  op - It is the operator being overloaded. It may be unary or binary operator. It is preceded by the keyword operator.  operator op - It is the function name, Where operator is a keyword.
  • 7.  Overloaded operator functions can be invoked by expressions such as: For unary operator: op x or op y eg: +a, -a, ++b, b--. For binary operator: x op y eg: a+b, a*b, a<b.  Only existing operators can be overloaded. New operators cannot be created.  The overloaded operator must have at least one operand that is of user-defined type.
  • 8.  We cannot change the basic meaning of an operator.  Overloaded operators follow the syntax rules of the original operators.  The following operators that cannot be overloaded. Size of Size of operator . Membership operator .* Pointer-to-member operator :: Scope resolution operator ?; Conditional Operator