Function Overloading in C++ (Using Different Parameters)

Function Overloading in C++ (Using Different Parameters)

22 Sep 2025
Intermediate
8.75K Views
10 min read
Learn with an interactive course and practical hands-on labs

Free C++ Online Course With Certificate

C++ Function Overloading: An Overview

We are now well aware of what are Functions in C++ and its various aspects like function parameters, call by value and call by reference, etc. We looked at all these in detail.

In this C++ tutorial, we will see how the same function can be used for different tasks i.e. C++ function overloading and its associated issues. To go a step further, take a look at our Free C++ Course With Certificate.

What is Function Overloading in C++?

If two or more functions have the same name but different numbers and types of parameters, they are known as overloaded functions. Let us understand it by this example.
int area(int a) {} //for area of square
int area(int l, int b) { } //for area of rectangle
float test(float b, float h) { } //for area of triangle

Here, you can see that all three functions have the same name area() and they perform the same operation of calculating area. The only difference is in the number and types of parameters they require to calculate the area of different shapes. Therefore, instead of defining three functions that should do the same thing, it is better to overload one. This is known as C++ Function Overloading.

Function overloading is a compile-time polymorphism technique in C++. Therefore, it becomes an important part of the OOPs concepts in C++. It promotes code reusability and understandability.

Remember: It can also happen that multiple functions have not only the same name but also the same numbers and types of parameters. This is not function overloading but function overriding. We will look into this after understanding Inheritance in C++ in the tutorials, Polymorphism in C++, and Function Overriding in C++ respectively.

C++ Function Overloading Using Different Types of Parameters

Example


#include <iostream>
using namespace std;

// function with 2 int type parameters
int area(int x, int y) {
 return x * y;
}

// function with float type parameter
float area(float x) {
 return x * x;
}

int main() {
 int result1 = area(70, 2); //function call for the function with 2 int type parameters
 float result2 = area(5.6); //function call for the function with float type parameter
 
 cout << "Area of rectangle using integer arguments: " << result1 << endl;
 cout << "Area of square using a float argument: " << result2 << endl;
 
 return 0;
} 

The above C++ code in C++ Compiler overloads the area() function to calculate the area of a rectangle and square withdifferent types of parameters. Based on the type of arguments in the function call, the corresponding function is called.

Output

Area of rectangle using integer arguments: 140
Area of rectangle using float arguments: 47.04

Read More - C++ Interview Interview Questions for Experienced

C++ Function Overloading Using Different Number of Parameters

Example


#include <iostream> 
using namespace std;

// function with 2 float type parameters
float area(float x, float y) {
 return x * y;
}

// function with a float type single parameter
float area(float x){
 return x * x;
}

int main() {
 float result1 = area(5.6, 8.4); //function call for the function with 2 float type parameters
 float result2 = area(3.5); //function call for the function with a float type single parameter
 cout << "Area of rectangle using float arguments: " << result1 << endl;
 cout << "Area of square using a float argument: " << result2 << endl;

 return 0;
} 

The above C++ code overloads the area() function to calculate the area of a rectangle and square with the same types of parameters but having different numbers. Based on the typeand number of arguments in the function call, the corresponding function is called.

Output

Area of rectangle using integer arguments: 140
Area of rectangle using float arguments: 47.04
Area of square using a float argument: 12.25

Points to Remember

  • C++ function overloading is not only a feature of user-defined functions in C++
  • Many standard library functions in C++ are also overloaded. E.g. the sqrt() function can take double, float, int, etc. as parameters. This is possible because the sqrt() function is overloaded in C++.
  • The return type of the overloaded functions may or may not be the same.
  • The parameters for each function must be in a distinct order.
  • The parameters for the functions must be distinct.

Advantages of C++ Function Overloading

  • We can create functions with distinct purposes but with the same name by using function overloading in C++.
  • It speeds up the program's execution.
  • The code is clearer and simpler to comprehend.
  • It reduces memory utilization and makes programs reusable.

Disadvantages of C++ Function Overloading

  • It prevents the overloading of functions with various return types.
  • The identical parameters cannot be overloaded in the case of a static function.
Summary
After reading this C++ Function Overloading article, your concept of functions must have been recalled and refreshed. You just need to practice more and more to get through with the concept. 
Without advanced React.js skills, you’ll be stuck in low-paying roles. Enroll in our React Certification Course now and break into high-demand jobs.
Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at ScholarHat)

He is a renowned Speaker, Solution Architect, Mentor, and 10-time Microsoft MVP (2016–2025). With expertise in AI/ML, GenAI, System Design, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development, he bridges traditional frameworks with next-gen innovations.

He has trained 1 Lakh+ professionals across the globe, authored 45+ bestselling eBooks and 1000+ technical articles, and mentored 20+ free courses. As a corporate trainer for leading MNCs like IBM, Cognizant, and Dell, Shailendra continues to deliver world-class learning experiences through technology & AI.
Live Training - Book Free Demo
Azure AI Engineer Certification Training
11 Oct
10:00AM - 12:00PM IST
Checkmark Icon
Get Job-Ready
Certification
Azure AI & Gen AI Engineer Certification Training Program
11 Oct
10:00AM - 12:00PM IST
Checkmark Icon
Get Job-Ready
Certification
AWS Developer Certification Training
12 Oct
05:30PM - 07:30PM IST
Checkmark Icon
Get Job-Ready
Certification
Advanced Full-Stack Java Developer Certification Training Course
12 Oct
05:30PM - 07:30PM IST
Checkmark Icon
Get Job-Ready
Certification
ASP.NET Core Certification Training
12 Oct
08:00PM - 10:00PM IST
Checkmark Icon
Get Job-Ready
Certification
Accept cookies & close this