-1
void sum(int x);
void sum(float x);

I don't understand why these function overloading statements create below error for sum(2.3):

call of overloaded sum(double) is ambiguous

But for the below two function overloading, it works well.

void sum(int x);
void sum(double x);
Animesh Kumar Paul
  • 2,241
  • 4
  • 26
  • 37

1 Answers1

1

2.3 is a double, and the compiler can't choose among converting to an int or to a float (both are subject to loss of precision).

Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69