C++:gcc/g++编译器错误logf不是std的成员



我编写了一个C++文件,其中包含一个使用std::logf()的函数。它包含这条线

float xx = std::logf(x) - 1.0f;

编译器给我以下错误:

math_functions.cpp: In function ‘int fclamp_log_to_int(float, int, int)’:
math_functions.cpp:49:21: error: ‘logf’ is not a member of ‘std’; did you mean ‘logb’?
49 |     float xx = std::logf(x) - 1.0f;
|                     ^~~~
|                     logb

我已包含cmath标头,根据https://en.cppreference.com/w/cpp/numeric/math/log

我的g++版本是

g++ (Debian 10.2.1-6) 10.2.1 20210110

并且我已经将标志CCD_ 3包括在我的CCD_。

logf更改为log编译时不会出现问题。

这是gcc的问题吗?

这是gcc问题吗?

是。据报道。公平地说,由于一个编辑错误导致C++17中固定的标准出现矛盾,std::logf是否需要存在还有些不清楚。

您可以使用std::log(float)来解决此问题。另一个解决方法是使用::logf,尽管这不是必要的,因为您可以使用std::log(float)

最新更新