Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

int and float in function overloading

I have two overloaded function like below:

void print(int i) { ... }
void print(float f) { ... }

Its giving me this error for print(1.2);:

error: call of overloaded 'print(double)' is ambiguous 

Can anyone explain me why?

like image 404
Shahriar Avatar asked Apr 07 '26 23:04

Shahriar


1 Answers

1.2 is a double literal not a float.

So the compiler requires an explicit disambiguation.

1.2f would work as that is a float literal.

like image 170
Bathsheba Avatar answered Apr 09 '26 13:04

Bathsheba