I wanted to know why I am getting the compilation error
call of overloaded 'my_add(double, double, double)' is ambiguous
when I am trying to overload my_add function as follows:
//=============== Start of Program ===========
#include <iostream.h>
int my_add( int x, int y , int z)
{
return (x+y+z);
}
float my_add( float x, float y , float z)
{
return (x+y+z);
}
int main (void)
{
cout<<my_add(5,6,1);
cout<<my_add(5.5,6.5,1.0);
}
//=============== End of Program ===========
However, the code compiles fine when I change the float
s to double
s in my_add( float x, float y , float z)
.
What I have learnt is that for overloading a function it's definitions should differ in number of parameters, order of parameters or type of parameters.
In my case, the two versions of the functions differ in type of parameters.
The IDE I am using is Code Blocks.