环境:

  • Ubuntu 16.04 64位
  • g++版本5.4.0

  • 这是代码:
    #include <numeric>
    ...
    auto g = std::gcd(10, 4);
    ...
    

    我在编译命令中打开了-std=c++17选项:
    g++ -m64 -std=c++17   -c -g -w -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
    

    然后我得到了错误:



    this webpage开始,从C++ 17开始引入std::gcd

    this webpage,我的g++版本支持C++ 17。

    但是为什么仍然存在错误?相同的代码可以在Visual Studio 2017中编译而不会出现任何错误。

    最佳答案

    std::gcd仅从GCC 7.1起可用。

    Table 1.5. C++ 2017 Implementation Status

    c&#43;&#43; - std::gcd无法在g&#43;&#43; 5.4.0中编译- &#39;gcd&#39;不是 &#39;std&#39;的成员-LMLPHP

    请参阅一致性查看器以获取多个GCC versions

    关于c++ - std::gcd无法在g++ 5.4.0中编译- 'gcd'不是 'std'的成员,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54746702/

    10-11 22:46
    查看更多