C++C++11C++14C++17Introduction to C++Learn C++

Discover Function Overloading in C++

Do you want to learn how to overload a function ? What is Function Overloading ? What does overloaded function means ? How we can use Function Overloading in C++ ? How we can use multiple parameter types in our functions ? Here we go,

Function Overloading is used to operate with the same function by defining it with different variable types. By using Function Overloading, a function can be used with the same name in different parameter types and multiple variations.

In previous posts about functions, we created an addition function add() that has a and b parameters and returns sum of a and b. C++ functions are the most flexible and effective functions for using memory and CPU operations. For example, using integer variables in a function is faster than using long integer variables. Also using correct types may have some benefits to use variables (i.e memory usage, conversion required, etc.). In programming sometimes we may want to use different types of variables and variable variations, here we use Function Overloading.

Let’s remember this integer addition example,

We can use this function as in this example below,

As same this function we can generate a new function to add floating numbers with a name change,

As you see we should use a new name addf() for the operation on the floating point numbers.

If we want to use same function name on both float and integer numbers, we can Overload this function by adding a new declarations and definitions with the same function names as below,

As you see we have same function name but both has different parameter types and return types while both are used to add a and b;

Get started building powerful apps with C++Builder!

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Learn C++

What Is The Priority Queue (std::priority_queue) In Modern C++?

C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

Worth reading...
Learn About Parameters Passed by Reference in Functions