C++ 编译器错误 : ambiguous call to overloaded function

标签 c++

string aux;
int maxy,auxx=0;

cin>>aux;

maxy= (int)sqrt(aux.size());

我得到:

1> error C2668: 'sqrt' : ambiguous call to overloaded function
1>        could be 'long double sqrt(long double)'
1>        or       'float sqrt(float)'
1>        or       'double sqrt(double)'

为什么?

最佳答案

string::size() 返回 size_t,而 sqrt 在其任何版本中都不接受它。所以编译器必须强制转换,并且不能选择什么 - 它们都可以。您必须进行明确的类型转换:

maxy = (int)sqrt((double)aux.size());

关于C++ 编译器错误 : ambiguous call to overloaded function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6233132/

相关文章:

c++ - 如何使用函数在C++中初始化静态成员

c++ - 如何覆盖子类中的抽象类构造函数

c++ - 带有单独 TU 的 x3 链接器错误

c++ - Qt Designer .ui 和 Visual Studio 事件处理

c++ - 为什么不排序工作

c++ - 检查类是否是模板特化

C++:0. 和 0.0 之间的区别?

c++ - 错误 : stray ‘\224’ in program after including external library

c++ - 以下单例实现线程安全吗?

c++ - 调试 Python ctypes 段错误