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

标签 c++ std

我在使用 XCode 编译库时遇到错误:

'powf' is not a member of 'std'

<cmath>包括在内。

谁能给我解释一下哪里出了问题?

最佳答案

直到 C++11,powf 只是一个 Microsoft-ism .它根本没有出现在 ISO 标准中,因此不太可能出现在 XCode 中,除非他们要适应 Microsoft 的怪异做法,我认为这不太可能。

另一方面,

pow 成为 C++ 库的一部分的时间更长,因为它在 C 库的早期迭代中并入了 C++ pre-11。改用它。

自 C++11 起,powf 确实 出现在 ISO 标准中并且是 std 命名空间的一部分。

尽管如此,还是有一些不兼容的实现,例如 gcc libstdc++。此摘录中的更多资源取自 cppreference talk page 中的讨论:

Answers posted above were correct before C++11, since C++98/03 hadn't referred C99 library yet. According to the current standard, powf is declared in namespace std when is included (explicitly mentioned since C++17, implicitly mentioned in C++11/14, see also N4659, N4140 and N3337). For std::powf, gcc libstdc++ is not compliant while clang libc++ is. --Fruderica (talk) 03:49, 19 February 2019 (PST)

See also this, more recent, SO answer: https://stackoverflow.com/a/54735351 --Cubbi (talk) 08:10, 19 February 2019 (PST)

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

相关文章:

c++ - Windows 上的 endian.h

c++ - 如何将 "warnings as error"规则添加到 Qt .pro 文件?

c++ - 如何从 `std::istream` 加载 XML 文档?

c++ - 如何返回标准文件流

c++ - 错误 : ‘log2’ is not a member of ‘std’

c++ - 为什么 std::sort 不要求用户指定模板类型?

c++ - 分发原始 msvcp.dll 或安装 vc_redist.exe

c++ - 命名 vector 的 vector 导致编译器错误

c++ - 事件派发器调用代码函数

c++ - 指向复数 <double> sin 的指针