我有两个重载函数,如下所示:
void print(int i) { ... }
void print(float f) { ... }
print(1.2);
给我这个错误:
error: call of overloaded 'print(double)' is ambiguous
谁能解释一下为什么?
最佳答案
1.2 是双字面量而不是 float 。
因此编译器需要明确的消歧。
1.2f 可以工作,因为它是一个 float 。
关于c++ - 函数重载中的 int 和 float,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34208397/