让我们看看以下函数重载声明
void funA(int);
void funA(float);
Run Code Online (Sandbox Code Playgroud)
然后我们调用这样的函数:
funA(1); // this will be ok.
Run Code Online (Sandbox Code Playgroud)
然而,
funA(1.333) // this will not ok..
Run Code Online (Sandbox Code Playgroud)
对于编译器,funA(int)和funA(float)将是不明确的..编译器将1.333值转换为整数(1)..虽然假设它是一个浮点值会更合适..
我正在使用g ++(GCC)4.8.2为什么编译器不会调用funA(float)呢?但是以下工作..
funA(static_cast<float>(1.333))
Run Code Online (Sandbox Code Playgroud)