Function Overloading in C++Last Updated : 12 Jan 2026 In C++, function overloading is a feature of object-oriented programming that enables multiple functions to have the same name but have distinct parameter lists (either in terms of type, number, or both). It makes the code more readable, reusable, and effective by allowing a function to handle different input types while maintaining a consistent interface. Function design is flexible because the compiler chooses the function to run based on the inputs supplied. It may be considered as an example of polymorphism in C++. Syntax:It has the following syntax: In this syntax, we have taken two function declarations that have the same name but different parameters: Simple Function Overloading Example:Let us take a program to illustrate the function overloading in C++. ExampleCompile and RunOutput: 35 21 14.1 Explanation: In this example, we have taken three function declarations that contain the same name but different parameters. How does Function Overloading Work in C++?There are several steps that helps us to understand how function overloading works in C++.
Types of Function Overloading in C++:In C++, function overloading depends on the function name and the number or types of parameters. The return type alone cannot differentiate overloaded functions. If two functions have identical parameter lists but different return types, a compilation error occurs due to ambiguity. There are three types of function overloading, and they are:
1. Function Overloading Based on Number of Parameters:Function overloading can create multiple functions with the same name but different parameters. Depending on how many arguments are provided in during function calls, the compiler chooses the right function. It improves the code's readability, flexibility, and maintainability. Syntax: It has the following syntax. C++ Function Overloading Based on Number of Parameters Example:A C++ program to illustrate Function Overloading Based on Number of Parameters. ExampleCompile and RunOutput: Age: 21 years Age: 28 years, Height: 5.8 meters Age: 32 years, Height: 6.2 meters, Name: John Explanation: In this example, we demonstrate function overloading by defining three printInfo functions with different parameter counts. It depends on how many arguments are passed. Each function prints information like age, height, and name. Various versions of printInfo are called with one, two, and three arguments in the main function, which demonstrates how function overloading allows multiple functions with the same name but different parameters to exist. 2. Function Overloading Based on Different Parameter Types:In this method, many functions have the same name but different data types for their parameters. It allows a function to handle a variety of inputs while retaining a consistent interface, which enhances the code readability and adaptability. Syntax: It has the following syntax. C++ Function Overloading Based on Different Parameter Types Example:ExampleCompile and RunOutput: An Integer value is: 27 The Double value is: 7.36 The String value is: Hello TpointTech Explanation: In this example, we demonstrate the function overloading based on different parameter types. The main function calls printInfo with various argument types, which triggers the appropriate function based on the argument's and data type. The application displays integer, double, and string values with corresponding labels. 3. Function Overloading Based on Different Parameter Order:Function overloading allows many functions to share a name as long as the number, type, and order of the parameters in each function's list differ. Changing the order of the parameters while maintaining their types is known as overloading based on different parameter orders. Syntax: It has the following syntax. C++ Function Overloading Based on Different Parameter Orders Example:ExampleCompile and RunOutput: Integer value is: 21, Double value is: 5.4 Double value is: 7.84, Integer value is: 19 Explanation: In this example, we demonstrate function overloading by defining two printInf() methods with similar parameters but in different ordering. The first variant prints an integer ID and a double score, whereas the second variant prints a double rating and an integer count. Use Cases for Function Overloading in C++:Several use cases for function overloading in C++ are as follows:
Main differences between Function Overloading and Operator OverloadingSeveral main differences between function overloading and operator overloading in C++ are as follows:
Main differences between Function Overloading and Function Overriding:Several main differences between function overloading and function overriding in C++ are as follows:
Next TopicFunction Overriding in C++ |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India