SlideShare a Scribd company logo
Function overloading
Definition and explanation… 
C++ allows you to specify more than one definition for a function which is called function 
overloading. 
An overloaded declaration is a declaration that had been declared with the same name as a 
previously declared declaration in the same scope. Both declarations have different arguments and 
obviously different definition (implementation). 
When you call an overloaded function the compiler determines the most appropriate definition to 
use by comparing the argument types you used to call the function with the parameter types 
specified in the definitions. 
You can have multiple definitions for the same function name in the same scope. The definition of 
the function must differ from each other by the types and/or the number of arguments in the 
argument list. You can not overload function declarations that differ only by return type.
/*Calling overloaded function num() with different argument/s.*/ 
#include <iostream> 
using namespace std; 
void num(int); 
void num{float); 
void num(int, float); 
int main() 
{ int a = 5; 
float b = 5.5; 
Num(a); 
num(b); 
num(a, b); 
return 0; } 
void num(int var) 
{ 
cout<<"Integer number: "<<var<<endl; 
} 
void num(float var) 
{ 
cout<<"Float number: "<<var<<endl; 
} 
void num(int var1, float var2) 
{ 
cout<<"Integer number: "<<var1; 
cout<<" And float number:"<<var2; 
}
Output 
Integer number: 5 
Float number: 5.5 
Integer number: 5 And float number: 5.5

More Related Content

PPTX
Classes function overloading
PPT
3 Function Overloading
PPTX
Function overloading
PPTX
Function overloading and overriding
PPTX
Function overloading
PPTX
Function overloading in c++
PPT
Function overloading(C++)
PDF
03 function overloading
Classes function overloading
3 Function Overloading
Function overloading
Function overloading and overriding
Function overloading
Function overloading in c++
Function overloading(C++)
03 function overloading

What's hot (20)

PPTX
Presentation on overloading
PDF
Operator overloading
PPT
FUNCTIONS IN c++ PPT
PDF
Functional Programming in JavaScript
PPTX
Function C++
PPT
C++ overloading
PPT
C++ Function
PPT
Functions in C++
PPTX
INLINE FUNCTION IN C++
PDF
Functions in C++
PPTX
Inline Functions and Default arguments
PPTX
Inline function
PPTX
C++ programming function
PPT
Functions in C++
PPTX
Functions in C++
PPT
CPP Language Basics - Reference
PPT
Functions in C++
PPTX
Types of function call
PPT
16717 functions in C++
 
PPTX
Function Parameters
Presentation on overloading
Operator overloading
FUNCTIONS IN c++ PPT
Functional Programming in JavaScript
Function C++
C++ overloading
C++ Function
Functions in C++
INLINE FUNCTION IN C++
Functions in C++
Inline Functions and Default arguments
Inline function
C++ programming function
Functions in C++
Functions in C++
CPP Language Basics - Reference
Functions in C++
Types of function call
16717 functions in C++
 
Function Parameters
Ad

Viewers also liked (20)

PDF
Vladimir_Suvorov_Big_data
PPT
Architecting for Big Data - Gartner Innovation Peer Forum Sept 2011
PDF
Understanding Big Data
PPTX
Charting the Course: Using Data in the Museum to Explore, Innovate, and Reach...
PPTX
Big Data for the CMO
PDF
ANTS and BIG DATA - The it outsourcing trend - ICTCom 2016
PPTX
Big Data Predictive Analytics with Revolution R Enterprise (Gartner BI Summit...
PDF
Big Data Taiwan 2014 Track2-1: SAP 善用足跡,預測未來 - 全方位的行銷視野
PDF
The IoT Food Chain – Picking the Right Dining Partner is Important with Dean ...
PDF
Growing Data Scientists by Amparo Alonso Betanzos
PDF
Inferring the effect of an event using CausalImpact by Kay H. Brodersen
PDF
Big Data Industry Insights 2015
PDF
Big Data Taiwan 2014 Track2-2: Informatica Big Data Solution
PDF
Big Data Analytics for the Industrial Internet of Things
PDF
Big Data Tornado - 2015 台灣 Big Data 企業經典應用案例分享
PPTX
A Brief History of Big Data
PPTX
Internet of Things and Big Data: Vision and Concrete Use Cases
DOCX
Paginas ampliadas
PDF
Mfhp12 c excel_4ed_solucoes
DOCX
Grafica grupal
Vladimir_Suvorov_Big_data
Architecting for Big Data - Gartner Innovation Peer Forum Sept 2011
Understanding Big Data
Charting the Course: Using Data in the Museum to Explore, Innovate, and Reach...
Big Data for the CMO
ANTS and BIG DATA - The it outsourcing trend - ICTCom 2016
Big Data Predictive Analytics with Revolution R Enterprise (Gartner BI Summit...
Big Data Taiwan 2014 Track2-1: SAP 善用足跡,預測未來 - 全方位的行銷視野
The IoT Food Chain – Picking the Right Dining Partner is Important with Dean ...
Growing Data Scientists by Amparo Alonso Betanzos
Inferring the effect of an event using CausalImpact by Kay H. Brodersen
Big Data Industry Insights 2015
Big Data Taiwan 2014 Track2-2: Informatica Big Data Solution
Big Data Analytics for the Industrial Internet of Things
Big Data Tornado - 2015 台灣 Big Data 企業經典應用案例分享
A Brief History of Big Data
Internet of Things and Big Data: Vision and Concrete Use Cases
Paginas ampliadas
Mfhp12 c excel_4ed_solucoes
Grafica grupal
Ad

Similar to Function overloading (20)

PPT
Function Overloading.ppt
PPT
FunctionOverloadingwithpolymorphismconcept.ppt
PPT
class12 3 Function Overloadingin ooooop .ppt
PPTX
Functions in C++ (OOP)
PPTX
Presentation on polymorphism in c++.pptx
PPTX
Silde of the cse fundamentals a deep analysis
PPT
OODP UNIT 2 Function overloading
PPTX
Function Overloading in C++ programming language
PPT
Function overloading in c++
PPT
Lecture 5
PPTX
function overloading
PPTX
Function_Overloading_in_CPP its uses and examples.
DOCX
Functions in c++
PPT
Polymorphism
PPT
Function overloading(c++)
PPT
Function oveloading
PDF
PPTX
Function Overloading Call by value and call by reference
PPTX
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
PPTX
Function overloading
Function Overloading.ppt
FunctionOverloadingwithpolymorphismconcept.ppt
class12 3 Function Overloadingin ooooop .ppt
Functions in C++ (OOP)
Presentation on polymorphism in c++.pptx
Silde of the cse fundamentals a deep analysis
OODP UNIT 2 Function overloading
Function Overloading in C++ programming language
Function overloading in c++
Lecture 5
function overloading
Function_Overloading_in_CPP its uses and examples.
Functions in c++
Polymorphism
Function overloading(c++)
Function oveloading
Function Overloading Call by value and call by reference
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Function overloading

Recently uploaded (20)

PDF
Basic Mud Logging Guide for educational purpose
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Lesson notes of climatology university.
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Classroom Observation Tools for Teachers
PDF
RMMM.pdf make it easy to upload and study
PPTX
master seminar digital applications in india
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Pharma ospi slides which help in ospi learning
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Basic Mud Logging Guide for educational purpose
102 student loan defaulters named and shamed – Is someone you know on the list?
human mycosis Human fungal infections are called human mycosis..pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Lesson notes of climatology university.
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
O7-L3 Supply Chain Operations - ICLT Program
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Classroom Observation Tools for Teachers
RMMM.pdf make it easy to upload and study
master seminar digital applications in india
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pharma ospi slides which help in ospi learning
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Microbial diseases, their pathogenesis and prophylaxis
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape

Function overloading

  • 2. Definition and explanation… C++ allows you to specify more than one definition for a function which is called function overloading. An overloaded declaration is a declaration that had been declared with the same name as a previously declared declaration in the same scope. Both declarations have different arguments and obviously different definition (implementation). When you call an overloaded function the compiler determines the most appropriate definition to use by comparing the argument types you used to call the function with the parameter types specified in the definitions. You can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. You can not overload function declarations that differ only by return type.
  • 3. /*Calling overloaded function num() with different argument/s.*/ #include <iostream> using namespace std; void num(int); void num{float); void num(int, float); int main() { int a = 5; float b = 5.5; Num(a); num(b); num(a, b); return 0; } void num(int var) { cout<<"Integer number: "<<var<<endl; } void num(float var) { cout<<"Float number: "<<var<<endl; } void num(int var1, float var2) { cout<<"Integer number: "<<var1; cout<<" And float number:"<<var2; }
  • 4. Output Integer number: 5 Float number: 5.5 Integer number: 5 And float number: 5.5