SlideShare a Scribd company logo
8
Most read
9
Most read
10
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.
INTRODUCTION
 In Binary operator overloading function, there should be one
argument to be passed.
 It is overloading of an operator operating on two operands.
#include<iostream>
class multiply
{
int first,second;
public:
void getdata(int a,int b)
{
first=a;
second=b;
}
Contd...,
void display()
{
cout<<“first=“<<first<<“second=“<<secon<<endl;
}
multiply operator *(multiply c);
};
void multiply::operator *(multiply c)
{
multiply temp;
temp.first=first*c.first;
temp.second=second*c.second;
return temp;
}
Contd..,
int main()
{
multiply obj1,obj2,obj3;
obj1.getdata(15,20);
obj2.getdata(3,45);
obj3=obj1*obj2;
obj3.display();
return 0;
}
Output:
45
900

More Related Content

PPT
Queue data structure
PPTX
Operator Overloading & Function Overloading
PPTX
Polymorphism In c++
PDF
Constructors and destructors
PPTX
Command line arguments
PPTX
Polymorphism in C++
PPTX
linked list in data structure
PPTX
Queue data structure
Operator Overloading & Function Overloading
Polymorphism In c++
Constructors and destructors
Command line arguments
Polymorphism in C++
linked list in data structure

What's hot (20)

PDF
Function overloading ppt
PPTX
Priority Queue in Data Structure
PPTX
Pointers,virtual functions and polymorphism cpp
PPT
Function overloading(c++)
PPTX
Static Data Members and Member Functions
PDF
C++ OOPS Concept
PPTX
Pointers in C Programming
PPTX
Arrays & Strings
PPSX
Files in c++
PPTX
Constructor and destructor
PPTX
Recursive Function
PPTX
sorting and its types
PPTX
Constructor ppt
PDF
Constructors and Destructors
PPTX
classes and objects in C++
PPTX
Inheritance in c++
PDF
C++ Files and Streams
PPTX
Inheritance in c++
PPSX
PPTX
Pointers in C
Function overloading ppt
Priority Queue in Data Structure
Pointers,virtual functions and polymorphism cpp
Function overloading(c++)
Static Data Members and Member Functions
C++ OOPS Concept
Pointers in C Programming
Arrays & Strings
Files in c++
Constructor and destructor
Recursive Function
sorting and its types
Constructor ppt
Constructors and Destructors
classes and objects in C++
Inheritance in c++
C++ Files and Streams
Inheritance in c++
Pointers in C
Ad

Similar to Binary operator overloading (20)

PPT
Unary operator overloading
PPT
Operator overloading in C++
PPTX
Operator overloading
PPTX
Operator overloading
PPTX
DOCX
Operator oveerloading
PPT
08 c++ Operator Overloading.ppt
PPT
08 c-operator-overloadingppt2563
PPT
Lec 26.27-operator overloading
PPT
Polymorphism and function overloading_new.ppt
PPTX
Operator overloading
PPT
Lec 28 - operator overloading
PPTX
Mca 2nd sem u-4 operator overloading
PPTX
Bca 2nd sem u-4 operator overloading
PPTX
Increment and Decrement operators in C++
PDF
Basics _of_Operator Overloading_Somesh_Kumar_SSTC
PPTX
Operator Overloading
PPTX
Object Oriented Programming using C++: Ch08 Operator Overloading.pptx
PDF
Ch-4-Operator Overloading.pdf
PPTX
Week7a.pptx
Unary operator overloading
Operator overloading in C++
Operator overloading
Operator overloading
Operator oveerloading
08 c++ Operator Overloading.ppt
08 c-operator-overloadingppt2563
Lec 26.27-operator overloading
Polymorphism and function overloading_new.ppt
Operator overloading
Lec 28 - operator overloading
Mca 2nd sem u-4 operator overloading
Bca 2nd sem u-4 operator overloading
Increment and Decrement operators in C++
Basics _of_Operator Overloading_Somesh_Kumar_SSTC
Operator Overloading
Object Oriented Programming using C++: Ch08 Operator Overloading.pptx
Ch-4-Operator Overloading.pdf
Week7a.pptx
Ad

Recently uploaded (20)

PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Lesson notes of climatology university.
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Presentation on HIE in infants and its manifestations
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
master seminar digital applications in india
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Types and Its function , kingdom of life
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Pharma ospi slides which help in ospi learning
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
Final Presentation General Medicine 03-08-2024.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Lesson notes of climatology university.
102 student loan defaulters named and shamed – Is someone you know on the list?
Computing-Curriculum for Schools in Ghana
Presentation on HIE in infants and its manifestations
O5-L3 Freight Transport Ops (International) V1.pdf
master seminar digital applications in india
VCE English Exam - Section C Student Revision Booklet
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Types and Its function , kingdom of life
Microbial diseases, their pathogenesis and prophylaxis
O7-L3 Supply Chain Operations - ICLT Program
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Pharma ospi slides which help in ospi learning
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
RMMM.pdf make it easy to upload and study
Final Presentation General Medicine 03-08-2024.pptx

Binary operator overloading

  • 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. INTRODUCTION  In Binary operator overloading function, there should be one argument to be passed.  It is overloading of an operator operating on two operands.
  • 8. #include<iostream> class multiply { int first,second; public: void getdata(int a,int b) { first=a; second=b; } Contd...,
  • 9. void display() { cout<<“first=“<<first<<“second=“<<secon<<endl; } multiply operator *(multiply c); }; void multiply::operator *(multiply c) { multiply temp; temp.first=first*c.first; temp.second=second*c.second; return temp; } Contd..,