You already have the bool ABC (int s, float t, int u)
function. If you declare another function named ABC too with only one parameter(s in your case), then you can use any of those functions with the same name:
bool ABC (typename s) //the return type can be anyithing, not necessarily bool
{
Another Function Implementation;
}
Now you can use the ABC function with one parameter and you have another version with 3 parameters with the same function name. That is what function overload means in action.
if(ABC(s)) //ABC(s,t,u) would be working too
Statement;
Note that the C++ language offers you a second way to handle optional parameters. By initializing the last n parameters with a specific value you will be able to leave some of them. In this case in the implementation of the function the left parameters will be assigned with the initial values:
bool ABC (int s, float t=0, int u=0)
{
Function Implementation;
}
int main()
{
//ABC() won`t work
ABC(2) //s=2; t=0; u=0;
ABC(2,3) //s=2; t=3; u=0;
ABC(2,3,4) //s=2; t=3; u=4
}
Be careful with that, because you can not set only s and u by calling the function with two paramaters. The order of parameters in your function declaration matters.
Furthermore assigning the parameters in your declaration with values which your function should not be got in normal way(these can be 0, INT_MIN (minimum value of a intiger value - defined in <climits>
) or anything else depend on your problem) you can check easily in your implementation the number of parameters using for calling the function:
#include <climits>
#include <cfloats>
bool ABC (int s, float t=FLT_MAX, int u=INT_MAX)
{
if(u == INT_MAX){...} //this means that you don`t set u
if(t == FLT_MAX){...} //this means you set only s
}