我在使用 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 namespacestd
when is included (explicitly mentioned since C++17, implicitly mentioned in C++11/14, see also N4659, N4140 and N3337). Forstd::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/