Function overloading is a feature in C++ where two or more functions can have the same name but different parameters.
Function overloading can be considered as an example of polymorphism feature in C++.
Following is a simple C++ example to demonstrate function overloading.
#include <iostream> using namespace std; void print(int i) { cout << " Here is int " << i << endl; } void print(double f) { cout << " Here is float " << f << endl; } void print(char const *c) { cout << " Here is char* " << c << endl; } int main() { print(10); print(10.10); print("ten"); return 0; } |
chevron_right
filter_none
Output:
Here is int 10 Here is float 10.1 Here is char* ten
- Function overloading and return type
- Functions that cannot be overloaded in C++
- Function overloading and const keyword
- Function Overloading vs Function Overriding in C++
Recent articles on function overloading in C++
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
Recommended Posts:
- Function Overloading vs Function Overriding in C++
- Function overloading and return type
- Function overloading and const keyword
- Function Overloading and float in C++
- Rules for operator overloading
- Does overloading work with Inheritance?
- Overloading in Java
- Different ways of Method Overloading in Java
- Constructor Overloading in Java
- Operator Overloading in C++
- Overloading stream insertion (<>) operators in C++
- Overloading Subscript or array index operator [] in C++
- C++ | Operator Overloading | Question 10
- Constructor Overloading in C++
- Namespaces in C++ | Set 4 (Overloading, and Exchange of Data in different Namespaces)
- Overloading New and Delete operator in c++
- C++ Program to concatenate two strings using Operator Overloading
- Operator overloading in C++ to print contents of vector, map, pair, ..
- Types of Operator Overloading in C++
- Increment (++) and Decrement (--) operator overloading in C++
Improved By : raHUL GUPTA 23

