C++ GCC 错误:"sqrtl"不是"std"的成员
c++ gcc error: 'sqrtl' is not a member of 'std'
当我尝试编译以下程序时,编译器给出了error: 'sqrtl' is not a member of 'std'
.
#include <cmath>
#include <iostream>
int main(){
std::cout << std::sqrtl(5.0) << "n";
return 0;
}
我想知道为什么会这样,所以我开始尝试。
当我删除sqrtl
前面的std::
时,程序编译并运行良好。当我另外删除#include <cmath>
时,编译器给出了error: 'sqrtl' was not declared in this scope
。
在这一点上,我真的很困惑。显然,cmath
中必须有一个函数sqrtl
,但它不是std
的成员?
当我在原始程序中用sqrt
替换sqrtl
时,程序编译并运行良好。当我在sqrt
面前删除std::
时也是如此.当我另外删除#include <cmath>
时,编译器给出了error: 'sqrt' was not declared in this scope
。
最后,我用sqrtf
做了同样的测试。同样的事情发生在sqrtl
.
我觉得奇怪的另一件事是,删除std::
首先可以让程序编译。特别是对于必须是std
成员的sqrt
,否则编译器会给出与sqrtl
和sqrtf
相同的错误。这尤其令人困惑,因为删除cout
前面的std::
会使编译器给我error: 'cout' was not declared in this scope
。
谁能解释为什么sqrtl
、sqrt
和sqrtf
的行为如此奇怪?sqrt
甚至是std
的成员吗?我怎样才能知道某个方法是否是std
的成员?
我知道删除std::
很容易解决,但出于一致性的目的,我喜欢在我的个人图书馆中的所有std
成员面前std::
。
这是一个错误。 Per [cmath.syn]sqrtl
是std
命名空间的成员。
namespace std { [...] float sqrt(float x); // see [library.c] double sqrt(double x); long double sqrt(long double x); // see [library.c] float sqrtf(float x); long double sqrtl(long double x); [...] }
这是法律代码,将在MSVS和Clang中编译。
GCC 中有一个错误报告,但尚未得到处理,因为它非常琐碎且资源有限。
- std::ofstream 作为类成员删除复制构造函数?
- 使用 std::index_sequence 初始化具有固定大小数组成员的 POD 结构容器
- std::to_string - 'to_string' 不是 'std' 的成员 - Visual Studio Code 1.42.0
- 使用 std::async 时死锁,将来作为成员
- 可变参数模板参数扩展 类型为 std::function 的类成员
- FreeFileSync C++错误:'byte'不是 'std' 的成员
- 为什么 std::sort 找不到合适的(静态成员)函数重载?
- 对带有唯一指针的 std::thread 使用类成员函数时出现编译错误
- 在模板化成员函数的返回类型中使用 std::enable_if 时的编译器差异
- 有没有办法避免为 std::variant 类成员中的所有类型编写构造函数?
- 是否允许类类型的 std::function 成员变量(不完整类型)?
- 访问 std:vector 的类成员 std:vector 在一个类中与另一个 std:vector
- std::异步与非静态成员函数
- 如何在 c++11 中静态断言 std::array 类成员进行排序?
- 将初始化器列表/聚合初始化转发到 std::array 成员
- C++ IDE 不会推断/自动完成对模板类中的 std::array 下标表达式的成员访问
- 在哪里可以找到 std::bitset 的数据成员?
- 没有'str'成员在 GCC 和 Clang 'std::basic_ostream<char>',但 MSVC 没有问题
- unique_ptr问题:不是'std'成员
- std::成员函数的异步调用