C++ GCC 错误:"sqrtl"不是"std"的成员

c++ gcc error: 'sqrtl' is not a member of 'std'

本文关键字:std 成员 不是 sqrtl 错误 C++ GCC      更新时间:2023-10-16

当我尝试编译以下程序时,编译器给出了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,否则编译器会给出与sqrtlsqrtf相同的错误。这尤其令人困惑,因为删除cout前面的std::会使编译器给我error: 'cout' was not declared in this scope

谁能解释为什么sqrtlsqrtsqrtf的行为如此奇怪?sqrt甚至是std的成员吗?我怎样才能知道某个方法是否是std的成员?

我知道删除std::很容易解决,但出于一致性的目的,我喜欢在我的个人图书馆中的所有std成员面前std::

这是一个错误。 Per [cmath.syn]sqrtlstd命名空间的成员。

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 中有一个错误报告,但尚未得到处理,因为它非常琐碎且资源有限。