c++ - 'round' 不是 'std' 的成员

标签 c++ g++

我正在尝试编译这段代码:

#include <cmath>
double gravity (double level) {
    return 0.02 * std::round(level);
}

但是 GCC 告诉我:

error: 'round' is not a member of 'std'

我知道我之前在 ISO C++98 中多次使用过 round 函数。不同寻常的是,round::round 都可以工作。

什么给了?

更新:我正在使用 g++ -std=c++98 -Wall -pedantic 进行编译。 切换到 std=c++0x 有效。

但是,如果 std::round 不起作用,为什么非限定/匿名 round::round 都可以工作?

最佳答案

std::round函数是 C++11,因此您需要使用 C++11 或启用的更新标准进行编译。

关于c++ - 'round' 不是 'std' 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12696764/

相关文章:

c++ - 警告 : conversion to 'double' from 'long int' may alter its value

c++ - 使用函数类型与函数指针作为 C++ 模板函数参数的区别?

c++ - 我如何构建一个从 git fork 克隆的单独的 boost 库?

c++ - std::string 使用 bool 初始化

c++ - 如何验证链接库?

c++ - 更好地理解 makefile - 在这种情况下如何生成 .o 文件

c++ - "C++ most vexing parse"的运行时行为

c++ - 如何使用 OpenCV 拉直曲线?

java - OpenCV JNI : Java/native handling of Mat - possibility for delete getting called twice?

c++ - std::array 编译时间扣除