![]() |
In C++, we can provide the default values for the input arguments into the functions and it is also supported in function overloading. In this article, we will learn how to use default arguments in function overloading in C++. Default Arguments in Function Overloading in C++We can define the default value in function overloading as we do it in the main function. But the problem occurs in situations where there are multiple matching function definitions for a function call and the compiler cannot decide which function body to execute. For Example, see the function overloading of: int func(int a) { //body } Both of the above functions can be called using the call func(10) leading to ambiguity issues. C++ Program to Use Default Arguments in Function OverloadingThe below example demonstrates how we can use default arguments in function overloading in C++. C++
Output
Values: 5 and 10 Values: 5 and 20 Values: 10 15 20
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |