C++变量重载歧义

标签 c++

对于下面这行代码:

for (int i = 1; i <= var; i++) { double inc = (14.0) - double(ceil(log10(i)))};

一直报错

Overloading ambiguity between "std::log10(double)" and "std::log10(float)"

我也尝试同时转换 incceil(log10(i))漂浮无济于事。想法?

最佳答案

是什么让您认为类型转换 incceil 会有帮助?编译器告诉您它无法确定您是想要 log10(float) 还是 log10(double)。您需要向编译器说明这一点

double inc = (14.0) - double(ceil(log10((float)i)));

double inc = (14.0) - double(ceil(log10((double)i)));

关于C++变量重载歧义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32577017/

相关文章:

C++ - GDB 错误问题

java - 在 C/Java/任何东西中加速/优化此代码

c++ - 在 Visual Studio 安装程序中添加 C++ 自定义操作

c++ - 在抛出 'std::bad_alloc' what(): std::bad_alloc 实例后调用终止

C++ 导入和使用 ADO

c++ - FreeBSD 上的 CMake 在/usr/local/include 中看不到 GL/gl.h

c++ - 重载 operator= 与非类类型

php - 编译错误: "g++: error trying to exec ' cc1plus': execvp: No such file or directory"

c++ - 显式实例化泛型结构的泛型成员函数

c++ - 如何使用前向声明类的成员函数?