I am new to C++ so please bear me and see my problem and help me to solve my problem.
Here I just tried to know which function will execute if there is a more than one function with same name But I left with an Error
error: call of overloaded ‘sum(int, int)’ is ambiguous
MY CODE
#include<iostream>
using namespace std;
// A function with default arguments, it can be called with
//2 arguments or 3 arguments or 4 arguments.
int sum(int x, int y, int z=0, int w=0)
{
return (x + y + z + w);
}
int sum(int x, int y, float z=0, float w=0)
{
return (x + y + z + w);
}
/* Driver program to test above function*/
int main()
{
cout << sum(10, 15) << endl;
cout << sum(10, 15, 25) << endl;
cout << sum(10, 15, 25, 30) << endl;
return 0;
}
Help what is happening here and what is the error I am getting an error