SlideShare a Scribd company logo
Presentation Topics
• Polymorphism
• Compile Time
• Run Time
• Function Overloading
• Operator Overloading
Polymorphism
Polymorphism is crucial feature of Object Oriented
Programming.
Polymorphism simply means one name having multiple
forms.
Polymorphism - Cont.
Definition:
Polymorphism is the ability to create a variable, a
function or an object that has more than one form.
Example:
For example:
The + (plus) operator in C++:
4 + 5 <-- Integer addition
3.14 + 2.0 <-- Floating point addition
s1 + "bar" <-- String concatenation!
Types of Polymorphism
• In compile time polymorphism, compiler is able to select
the appropriate function a particular call at the compile
time.
• In run time polymorphism, an appropriate member
function is selected while the program is running.
Benefits of Polymorphism
Simplicity
Extensibility
Kinds of Polymorphism
• Runtime/Dynamic polymorphism (Based on virtual
methods)
• Compile time/Static polymorphism (Based on
templates)
Runtime polymorphism
• Runtime binding between abstract type and concrete type
• Enforces a common interface for all derived types via the
base class
• Enforces an ‘Is-A’ relationship
• Used extensively in OO frameworks
• Templates eating into parts of its territory
Compile time Polymorphism
• Compile time binding between abstract type and concrete
type
• Concrete types need not belong to the same inheritance
hierarchy. They just need to meet the ‘Constraints’
imposed by the generic type. So, more generic than the
virtuals
• Foundation of ‘Generic programming’ or programming
based on ‘Concepts’ (Eg: STL)
• A very ‘Happening area’ in C++ right now (See TR1,
Boost, C++0x...)
Introduction
• Operator overloading
– Enabling C++’s operators to work with class objects
– Using traditional operators with user-defined objects
– Requires great care; when overloading is misused, program difficult to
understand
– Examples of already overloaded operators
• Operator << is both the stream-insertion operator and the bitwise left-
shift operator
• + and -, perform arithmetic on multiple types
Introduction
• Overloading an operator
–Write function definition as normal
–Function name is keyword operator followed by the
symbol for the operator being overloaded
–operator+ used to overload the addition operator (+)
Restrictions on Operator Overloading
• Restrictions on Operator Overloading
Operators that can be overloaded
+ - * / % ^ & |
~ ! = < > += -= *=
/= %= ^= &= |= << >> >>=
<<= == != <= >= && || ++
-- ->* , -> [] () new delete
new[] delete[]
C++ Operators that cannot be overloaded
Operators that cannot be overloaded
. .* :: ?: sizeof
Operators that cannot be overloaded
. .* :: ?: sizeof
Restrictions on Operator Overloading
• Overloading restrictions
– Precedence of an operator cannot be changed
– Associativity of an operator cannot be changed
– Arity (number of operands) cannot be changed
• Unary operators remain unary, and binary operators remain
binary
• Operators &, *, + and - each have unary and binary versions
• Unary and binary versions can be overloaded separately
• Thank You !!
Restrictions on Operator Overloading
• No new operators can be created
– Use only existing operators
• No overloading operators for built-in types
– Cannot change how two integers are added
– Produces a syntax error
In C++, two or more functions can share
the same name as long as their parameter
declarations are different.
In this situation, the functions that share
the same name are said to be overloaded,
and the process is referred to as function
overloading
To see why function overloading is important,
first consider three functions defined by the C subset:
abs(), labs(), and fabs().
abs() returns the absolute value of an integer,
labs() returns the absolute value of a long, and
fabs() returns the absolute value of a double.
Function Overloading – DEFINITION
• It is the process of using the same name for two or
more functions.
The secret to overloading is that each redefinition of
the function must use
either-
• different types of parameters
• different number of parameters.
The key to function overloading is a function’s argument list.
A function’s argument list is known as its signature.
Example :
Different types of arguments
void print(int a);
void print (double b);
void print(char c);
Different number of
parameters
void area(float r);
void area(float l, float b);
void area(float a, float b, float
c);
STEPS FOR FINDING BEST MATCH
• The actual arguments are compared with formal
arguments of the overloaded functions and the best
match is found through a number of steps.
•
In order to find the best match, the compiler follows
the steps given below:
STEP - 1 : Search for an exact match
•
If the type of the actual and formal argument is
exactly the same, the compiler invokes that function.
void print(int x); // function #1
void print(float p); // function #2
void print(char c); // function #3
------------
-------------
print(5.3); //invokes the function #2
STEP- 2 : A match through promotion
•
If no exact match is found, an attempt is made to
achieve a match through promotion.
void print(int x); // function #1
void print(float p); // function #2
void print(double f); // function #3
------------
-------------
print(‘c’); //matches the function #1 through
promotion
THANKS....

More Related Content

What's hot

Loop optimization
Loop optimizationLoop optimization
Loop optimization
Vivek Gandhi
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
Md. Ashraful Islam
 
Function class in c++
Function class in c++Function class in c++
Function class in c++
Kumar
 
Code optimization
Code optimizationCode optimization
Code optimization
Pradip Bhattarai
 
Inline assembly language programs in c
Inline assembly language programs in cInline assembly language programs in c
Inline assembly language programs in c
Tech_MX
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
Dheeraj Kataria
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Faisal Shehzad
 
Optimization
OptimizationOptimization
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
United International University
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
Northeastern University
 
Code optimisation presnted
Code optimisation presntedCode optimisation presnted
Code optimisation presnted
bhavanatmithun
 
Code optimization
Code optimizationCode optimization
Code optimization
veena venugopal
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
Akhil Kaushik
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
GrejoJoby1
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
Jenish Patel
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
Siva Sathya
 

What's hot (17)

Loop optimization
Loop optimizationLoop optimization
Loop optimization
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
 
Function class in c++
Function class in c++Function class in c++
Function class in c++
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Inline assembly language programs in c
Inline assembly language programs in cInline assembly language programs in c
Inline assembly language programs in c
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
 
Optimization
OptimizationOptimization
Optimization
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
 
Code optimisation presnted
Code optimisation presntedCode optimisation presnted
Code optimisation presnted
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
 

Similar to Polymorphism

OOPS-Seminar.pdf
OOPS-Seminar.pdfOOPS-Seminar.pdf
OOPS-Seminar.pdf
Rithiga6
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
Suraj Bora
 
Operator overloading (binary)
Operator overloading (binary)Operator overloading (binary)
Operator overloading (binary)
Tirthika Bandi
 
Presentation on polymorphism in c++.pptx
Presentation on polymorphism in c++.pptxPresentation on polymorphism in c++.pptx
Presentation on polymorphism in c++.pptx
vishwadeep15
 
OODP UNIT 2 Function overloading
OODP UNIT 2 Function overloadingOODP UNIT 2 Function overloading
OODP UNIT 2 Function overloading
Shanmuganathan C
 
Operator overloading C++
Operator overloading C++Operator overloading C++
Operator overloading C++
Lahiru Dilshan
 
3d7b7 session4 c++
3d7b7 session4 c++3d7b7 session4 c++
3d7b7 session4 c++
Mukund Trivedi
 
C++ overloading
C++ overloadingC++ overloading
C++ overloading
sanya6900
 
C++_overloading.ppt
C++_overloading.pptC++_overloading.ppt
C++_overloading.ppt
Satyanandaram Nandigam
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
Ralph Weber
 
11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx
AtharvPotdar2
 
oops.pptx
oops.pptxoops.pptx
oops.pptx
ASHWINAIT2021
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Amir Ali
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
prabhat kumar
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
Aabha Tiwari
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading
Charndeep Sekhon
 
OOP_UnitIII.pdf
OOP_UnitIII.pdfOOP_UnitIII.pdf
OOP_UnitIII.pdf
SuyogSabale1
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
Cpp (C++)
Cpp (C++)Cpp (C++)
Cpp (C++)
Jay Patel
 
Polymorphism 140527082302-phpapp01
Polymorphism 140527082302-phpapp01Polymorphism 140527082302-phpapp01
Polymorphism 140527082302-phpapp01
Engr.Tazeen Ahmed
 

Similar to Polymorphism (20)

OOPS-Seminar.pdf
OOPS-Seminar.pdfOOPS-Seminar.pdf
OOPS-Seminar.pdf
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
 
Operator overloading (binary)
Operator overloading (binary)Operator overloading (binary)
Operator overloading (binary)
 
Presentation on polymorphism in c++.pptx
Presentation on polymorphism in c++.pptxPresentation on polymorphism in c++.pptx
Presentation on polymorphism in c++.pptx
 
OODP UNIT 2 Function overloading
OODP UNIT 2 Function overloadingOODP UNIT 2 Function overloading
OODP UNIT 2 Function overloading
 
Operator overloading C++
Operator overloading C++Operator overloading C++
Operator overloading C++
 
3d7b7 session4 c++
3d7b7 session4 c++3d7b7 session4 c++
3d7b7 session4 c++
 
C++ overloading
C++ overloadingC++ overloading
C++ overloading
 
C++_overloading.ppt
C++_overloading.pptC++_overloading.ppt
C++_overloading.ppt
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx
 
oops.pptx
oops.pptxoops.pptx
oops.pptx
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading
 
OOP_UnitIII.pdf
OOP_UnitIII.pdfOOP_UnitIII.pdf
OOP_UnitIII.pdf
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
c++ UNIT II.pptx
 
Cpp (C++)
Cpp (C++)Cpp (C++)
Cpp (C++)
 
Polymorphism 140527082302-phpapp01
Polymorphism 140527082302-phpapp01Polymorphism 140527082302-phpapp01
Polymorphism 140527082302-phpapp01
 

More from sana younas

7 habits of highly effective people
7 habits of highly effective people7 habits of highly effective people
7 habits of highly effective people
sana younas
 
Connectivity of graphs
Connectivity of graphsConnectivity of graphs
Connectivity of graphs
sana younas
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithm
sana younas
 
Binary search
Binary searchBinary search
Binary search
sana younas
 
circular linklist
circular linklistcircular linklist
circular linklist
sana younas
 
Link list 2
Link list 2Link list 2
Link list 2
sana younas
 
Link list 1
Link list 1Link list 1
Link list 1
sana younas
 
Heapsort 1
Heapsort 1Heapsort 1
Heapsort 1
sana younas
 
Arrays
ArraysArrays
Arrays
sana younas
 
Enterpise system
Enterpise systemEnterpise system
Enterpise system
sana younas
 
Database administration
Database administrationDatabase administration
Database administration
sana younas
 
Encoders
EncodersEncoders
Encoders
sana younas
 
Universal logic gate
Universal logic gateUniversal logic gate
Universal logic gate
sana younas
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
sana younas
 
Memory management
Memory managementMemory management
Memory management
sana younas
 
Parallel adders
Parallel addersParallel adders
Parallel adders
sana younas
 

More from sana younas (16)

7 habits of highly effective people
7 habits of highly effective people7 habits of highly effective people
7 habits of highly effective people
 
Connectivity of graphs
Connectivity of graphsConnectivity of graphs
Connectivity of graphs
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithm
 
Binary search
Binary searchBinary search
Binary search
 
circular linklist
circular linklistcircular linklist
circular linklist
 
Link list 2
Link list 2Link list 2
Link list 2
 
Link list 1
Link list 1Link list 1
Link list 1
 
Heapsort 1
Heapsort 1Heapsort 1
Heapsort 1
 
Arrays
ArraysArrays
Arrays
 
Enterpise system
Enterpise systemEnterpise system
Enterpise system
 
Database administration
Database administrationDatabase administration
Database administration
 
Encoders
EncodersEncoders
Encoders
 
Universal logic gate
Universal logic gateUniversal logic gate
Universal logic gate
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Memory management
Memory managementMemory management
Memory management
 
Parallel adders
Parallel addersParallel adders
Parallel adders
 

Recently uploaded

South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 

Recently uploaded (20)

South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 

Polymorphism

  • 1.
  • 2. Presentation Topics • Polymorphism • Compile Time • Run Time • Function Overloading • Operator Overloading
  • 3.
  • 4. Polymorphism Polymorphism is crucial feature of Object Oriented Programming. Polymorphism simply means one name having multiple forms.
  • 5. Polymorphism - Cont. Definition: Polymorphism is the ability to create a variable, a function or an object that has more than one form.
  • 6. Example: For example: The + (plus) operator in C++: 4 + 5 <-- Integer addition 3.14 + 2.0 <-- Floating point addition s1 + "bar" <-- String concatenation!
  • 7. Types of Polymorphism • In compile time polymorphism, compiler is able to select the appropriate function a particular call at the compile time. • In run time polymorphism, an appropriate member function is selected while the program is running.
  • 9. Kinds of Polymorphism • Runtime/Dynamic polymorphism (Based on virtual methods) • Compile time/Static polymorphism (Based on templates)
  • 10. Runtime polymorphism • Runtime binding between abstract type and concrete type • Enforces a common interface for all derived types via the base class • Enforces an ‘Is-A’ relationship • Used extensively in OO frameworks • Templates eating into parts of its territory
  • 11. Compile time Polymorphism • Compile time binding between abstract type and concrete type • Concrete types need not belong to the same inheritance hierarchy. They just need to meet the ‘Constraints’ imposed by the generic type. So, more generic than the virtuals • Foundation of ‘Generic programming’ or programming based on ‘Concepts’ (Eg: STL) • A very ‘Happening area’ in C++ right now (See TR1, Boost, C++0x...)
  • 12.
  • 13. Introduction • Operator overloading – Enabling C++’s operators to work with class objects – Using traditional operators with user-defined objects – Requires great care; when overloading is misused, program difficult to understand – Examples of already overloaded operators • Operator << is both the stream-insertion operator and the bitwise left- shift operator • + and -, perform arithmetic on multiple types
  • 14. Introduction • Overloading an operator –Write function definition as normal –Function name is keyword operator followed by the symbol for the operator being overloaded –operator+ used to overload the addition operator (+)
  • 15. Restrictions on Operator Overloading • Restrictions on Operator Overloading Operators that can be overloaded + - * / % ^ & | ~ ! = < > += -= *= /= %= ^= &= |= << >> >>= <<= == != <= >= && || ++ -- ->* , -> [] () new delete new[] delete[]
  • 16. C++ Operators that cannot be overloaded Operators that cannot be overloaded . .* :: ?: sizeof Operators that cannot be overloaded . .* :: ?: sizeof
  • 17. Restrictions on Operator Overloading • Overloading restrictions – Precedence of an operator cannot be changed – Associativity of an operator cannot be changed – Arity (number of operands) cannot be changed • Unary operators remain unary, and binary operators remain binary • Operators &, *, + and - each have unary and binary versions • Unary and binary versions can be overloaded separately • Thank You !!
  • 18. Restrictions on Operator Overloading • No new operators can be created – Use only existing operators • No overloading operators for built-in types – Cannot change how two integers are added – Produces a syntax error
  • 19.
  • 20. In C++, two or more functions can share the same name as long as their parameter declarations are different. In this situation, the functions that share the same name are said to be overloaded, and the process is referred to as function overloading
  • 21. To see why function overloading is important, first consider three functions defined by the C subset: abs(), labs(), and fabs(). abs() returns the absolute value of an integer, labs() returns the absolute value of a long, and fabs() returns the absolute value of a double.
  • 22. Function Overloading – DEFINITION • It is the process of using the same name for two or more functions. The secret to overloading is that each redefinition of the function must use either- • different types of parameters • different number of parameters.
  • 23. The key to function overloading is a function’s argument list. A function’s argument list is known as its signature. Example : Different types of arguments void print(int a); void print (double b); void print(char c); Different number of parameters void area(float r); void area(float l, float b); void area(float a, float b, float c);
  • 24. STEPS FOR FINDING BEST MATCH • The actual arguments are compared with formal arguments of the overloaded functions and the best match is found through a number of steps. • In order to find the best match, the compiler follows the steps given below:
  • 25. STEP - 1 : Search for an exact match • If the type of the actual and formal argument is exactly the same, the compiler invokes that function. void print(int x); // function #1 void print(float p); // function #2 void print(char c); // function #3 ------------ ------------- print(5.3); //invokes the function #2
  • 26. STEP- 2 : A match through promotion • If no exact match is found, an attempt is made to achieve a match through promotion. void print(int x); // function #1 void print(float p); // function #2 void print(double f); // function #3 ------------ ------------- print(‘c’); //matches the function #1 through promotion