c ++ gcc错误:“ sqrtl”不是“ std”的成员

Smi*_*aft 2 c++ gcc std cmath

当我尝试编译以下程序时,编译器给出error: 'sqrtl' is not a member of 'std'

#include <cmath>
#include <iostream>
int main(){
    std::cout << std::sqrtl(5.0) << "\n";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我想知道为什么会这样,所以我开始尝试。

当我std::sqrtl程序前面删除时,编译并运行良好。当我另外删除时#include <cmath>,编译器给出error: 'sqrtl' was not declared in this scope

在这一点上我真的很困惑。有明确必须是一个函数sqrtlcmath,但它不是成员std

当我更换sqrtlsqrt原程序,该程序编译和运行良好。当我std::在前面移走时也是如此sqrt。当我另外删除时#include <cmath>,编译器给出error: 'sqrt' was not declared in this scope

最后,我对进行了相同的测试sqrtf。与发生相同的事情sqrtl

我觉得很奇怪的另一件事是,删除std::程序首先使程序可以编译。特别是with sqrt必须是的成员,std否则编译器将给出与sqrtl和相同的错误sqrtf。这特别令人困惑,因为std::cout编译器前面删除会给我error: 'cout' was not declared in this scope

谁能解释为什么sqrtlsqrt并且sqrtf表现得如此奇怪?是sqrt的,即使一员std?我如何找出某个方法是否为成员std

我知道删除std::是一个简单的修复程序,但是出于一致性的目的,我希望在我的个人图书馆中std::的所有std成员面前。

Nat*_*ica 5

这是一个错误。每个[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);
      [...]
}
Run Code Online (Sandbox Code Playgroud)

这是合法代码,将在MSVSClang中进行编译。

GCC中有一个有关此问题错误报告,但由于它很琐碎且资源有限,因此尚未得到解决。