SlideShare a Scribd company logo
1 of 17
Download to read offline
PRESENTED BY,
NAME: RITHIGA.M
REG NO:20BCA0052
OBJECT ORIENTED
PROGRAMMING
Contents:
• Introduction
• What is Operator overloading?
• Concept of Operator overloading
• Syntax of Operator overloading
• Rules for Operator overloading
• Advantages of Operator overloading
• Disadvantages of Operator overloading
• Example
• Conclusion
Introduction:
• Operator overloading is an important concept in C++.
• It is a type of polymorphism in which an operator is
overloaded to give user defined meaning to it.
• Overloaded operator is used to perform operation on user-
defined data type.
What is Operator overloading?
• C++ allows you to specify more than one definition for an
operator in the same scope, which is called operator
overloading.
• Operator overloading provides ability to an operator to
perform other manipulation.
• It preserves the original function of the operators and work
with user-defined types only.
Operations that can be perform:
1. Athematic operations: + – * / %
2. Logical operations: && and ||
3. Relational operations: == != >= <=
4. Pointer operators: & and *
5. Memory management operator: new, delete []
Operator overloading:
Concept of Operator overloading:
• Operator overloading is a compile-time polymorphism in
which the operator is overloaded to provide the special
meaning to the user-defined data type.
• Operators overloading is used to overloaded or refines
most of the operators available in C++.
Syntax of Operator overloading :
class ClassName
{
...
public:
…
return-type operator op(params-line)
{
//body of the function
…
}
…
};
Rules for Operator overloading:
• Only built-in operators can be overloaded. New operators can
not be created.
• Arity of the operators cannot be changed.
• Precedence and associativity of the operators cannot be
changed.
• Overloaded operators cannot have default arguments expect
the function call operator() which can have default arguments.
• Operators cannot be overloaded for built in types only. At
least one operand must be used defined type.
Rules cont:
• Assignment (=),subscript ([]),function call(“()”); and
member selection (->) operators must be defined as member
functions.
• Expect the operators specified in point 6, all other operators
can be either member functions or a non member functions.
• Some operators like (assignment)=, (address)& and comma(,)
are by default overloaded.
Advantages of Operator overloading:
• The main advantage of function overloading is that it
improves code readability and allows code reusability.
• Operator overloading enables programmers to use notation
closer to the target domain.
• Operator overloading provides similar syntactic support of
build-in types to user-defined types.
• Operator overloading makes the program easier to understand.
• It speeds up the execution of the program.
Disadvantages of Operator overloading:
• We can only overloaded the operators that exist and cannot
cerate new operators or rename existing operators.
• It is not possible to change the number of operands of an
operator supports.
• Conditional[?:], size of , scope(::), member selector(.),
member pointer selector(.*)and the casting operators.
• All operators keep their default precedence and
associations(what they use for). Only built-in operators can
be overloaded.
• Atleast one of the operands in overloaded must be user-
defined which means we cannot overload the minus operator
to work with one integer and one double.
Example:
• Write a program that adds and subtracts two integer values
using binary C++ Operator Overloading:
include <iostream>
#include<conio.h>
using namespace std;
class temp
{
private:
int data;
public:
void getvalue()
{
cin>>data;
}
temp operator+(temp ob)
{
temp t;
t.data=data + ob.data;
return t;
}
temp operator- (temp ob)
{
temp t;
t.data = data - ob.data;
return t;
}
int display()
{
return data;
}
};
int main()
{
temp obj1, obj2, sum, sub;
cout<<"enter an integer value for obj1: ";
obj1.getvalue();
cout<<"Enter an integer value for obj2: ";
obj2.getvalue();
sum= obj1+obj2;
sub=obj1-obj2;
cout<<"Addition result is = "<<sum.display()<<endl;
cout<<"Subtraction result is = "<<sub.display()<<endl;
getch();
}
Output:
Conclusion:
• Operator overloading is one of the feature of C++ that’s
implements compile time polymorphism.
• Overloading code should be written with greater care.
• Meaning of the operator should be preserved.
• Use any of the two method for declaring the operator
function.
THE END

More Related Content

Similar to OOPS-Seminar.pdf

OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++Aabha Tiwari
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingArunaDevi63
 
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 overloadingPrincess Sam
 
Operator overloading C++
Operator overloading C++Operator overloading C++
Operator overloading C++Lahiru Dilshan
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingKumar
 
Operator overloadng
Operator overloadngOperator overloadng
Operator overloadngpreethalal
 
OperatorOverloading.ppt
OperatorOverloading.pptOperatorOverloading.ppt
OperatorOverloading.pptasadmujtaba001
 
NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANINikul4470
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloadingPrincess Sam
 
9781285852744 ppt ch13
9781285852744 ppt ch139781285852744 ppt ch13
9781285852744 ppt ch13Terry Yoast
 
Synapse india complain sharing info on chapter 8 operator overloading
Synapse india complain sharing info on chapter 8   operator overloadingSynapse india complain sharing info on chapter 8   operator overloading
Synapse india complain sharing info on chapter 8 operator overloadingSynapseindiaComplaints
 

Similar to OOPS-Seminar.pdf (20)

OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading
 
Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloading
 
Oops
OopsOops
Oops
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
3d7b7 session4 c++
3d7b7 session4 c++3d7b7 session4 c++
3d7b7 session4 c++
 
Operator overloading C++
Operator overloading C++Operator overloading C++
Operator overloading C++
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Operator overloadng
Operator overloadngOperator overloadng
Operator overloadng
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
OperatorOverloading.ppt
OperatorOverloading.pptOperatorOverloading.ppt
OperatorOverloading.ppt
 
NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANI
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
9781285852744 ppt ch13
9781285852744 ppt ch139781285852744 ppt ch13
9781285852744 ppt ch13
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Synapse india complain sharing info on chapter 8 operator overloading
Synapse india complain sharing info on chapter 8   operator overloadingSynapse india complain sharing info on chapter 8   operator overloading
Synapse india complain sharing info on chapter 8 operator overloading
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 

Recently uploaded

Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 

Recently uploaded (20)

Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 

OOPS-Seminar.pdf

  • 1. PRESENTED BY, NAME: RITHIGA.M REG NO:20BCA0052 OBJECT ORIENTED PROGRAMMING
  • 2. Contents: • Introduction • What is Operator overloading? • Concept of Operator overloading • Syntax of Operator overloading • Rules for Operator overloading • Advantages of Operator overloading • Disadvantages of Operator overloading • Example • Conclusion
  • 3. Introduction: • Operator overloading is an important concept in C++. • It is a type of polymorphism in which an operator is overloaded to give user defined meaning to it. • Overloaded operator is used to perform operation on user- defined data type.
  • 4. What is Operator overloading? • C++ allows you to specify more than one definition for an operator in the same scope, which is called operator overloading. • Operator overloading provides ability to an operator to perform other manipulation. • It preserves the original function of the operators and work with user-defined types only.
  • 5. Operations that can be perform: 1. Athematic operations: + – * / % 2. Logical operations: && and || 3. Relational operations: == != >= <= 4. Pointer operators: & and * 5. Memory management operator: new, delete []
  • 7. Concept of Operator overloading: • Operator overloading is a compile-time polymorphism in which the operator is overloaded to provide the special meaning to the user-defined data type. • Operators overloading is used to overloaded or refines most of the operators available in C++.
  • 8. Syntax of Operator overloading : class ClassName { ... public: … return-type operator op(params-line) { //body of the function … } … };
  • 9. Rules for Operator overloading: • Only built-in operators can be overloaded. New operators can not be created. • Arity of the operators cannot be changed. • Precedence and associativity of the operators cannot be changed. • Overloaded operators cannot have default arguments expect the function call operator() which can have default arguments. • Operators cannot be overloaded for built in types only. At least one operand must be used defined type.
  • 10. Rules cont: • Assignment (=),subscript ([]),function call(“()”); and member selection (->) operators must be defined as member functions. • Expect the operators specified in point 6, all other operators can be either member functions or a non member functions. • Some operators like (assignment)=, (address)& and comma(,) are by default overloaded.
  • 11. Advantages of Operator overloading: • The main advantage of function overloading is that it improves code readability and allows code reusability. • Operator overloading enables programmers to use notation closer to the target domain. • Operator overloading provides similar syntactic support of build-in types to user-defined types. • Operator overloading makes the program easier to understand. • It speeds up the execution of the program.
  • 12. Disadvantages of Operator overloading: • We can only overloaded the operators that exist and cannot cerate new operators or rename existing operators. • It is not possible to change the number of operands of an operator supports. • Conditional[?:], size of , scope(::), member selector(.), member pointer selector(.*)and the casting operators. • All operators keep their default precedence and associations(what they use for). Only built-in operators can be overloaded. • Atleast one of the operands in overloaded must be user- defined which means we cannot overload the minus operator to work with one integer and one double.
  • 13. Example: • Write a program that adds and subtracts two integer values using binary C++ Operator Overloading: include <iostream> #include<conio.h> using namespace std; class temp { private: int data; public: void getvalue() { cin>>data; }
  • 14. temp operator+(temp ob) { temp t; t.data=data + ob.data; return t; } temp operator- (temp ob) { temp t; t.data = data - ob.data; return t; } int display() { return data; } }; int main() { temp obj1, obj2, sum, sub;
  • 15. cout<<"enter an integer value for obj1: "; obj1.getvalue(); cout<<"Enter an integer value for obj2: "; obj2.getvalue(); sum= obj1+obj2; sub=obj1-obj2; cout<<"Addition result is = "<<sum.display()<<endl; cout<<"Subtraction result is = "<<sub.display()<<endl; getch(); } Output:
  • 16. Conclusion: • Operator overloading is one of the feature of C++ that’s implements compile time polymorphism. • Overloading code should be written with greater care. • Meaning of the operator should be preserved. • Use any of the two method for declaring the operator function.