C ++ 11实验函数

时间:2014-11-20 15:36:36

标签: c++ c++11

每次我使用其中一个新类C ++ 11提供类似chrono.h并使用GCC编译它时它警告我C ++ 11函数仍然是实验性的,必须启用一个特殊标志才能使用。

2014年底,在写这篇文章的那一刻,为什么在至少3。5年后,GCC仍然将C ++ 11标记为"实验" ,经过这些年,C ++ 11为我们提供的一些功能还没有实现?

如果是这样,怎么回事?

代码:

#include <chrono>
#include <thread>
int main()
{
    std::this_thread::sleep_for(std::chrono::milliseconds(3000));
    return 0;
}

编译行: g++ Source.cpp -o test.exe

GCC版本: g ++(x86_64-posix-seh-rev0,由MinGW-W64项目构建)4.9.2版权所有(C)2014 Free Software Foundation,Inc。

GCC吐出: C:/Program Files/mingw-w64/x86_64-4.9.2-posix-seh-rt_v3-rev0/mingw64/x86_64-w64- mingw32/include/c++/bits/c++0x_warning.h:32:2: error: #error This file requires G compiler and library support for the ISO C++ 2011 standard. This support is curr ently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 comp iler options.

1 个答案:

答案 0 :(得分:5)

  

一旦我添加。 &#39; -std = C ++ 11&#39;对于编译器选项,我不再收到错误/警告消息,但我已经意识到了这一点。我很困惑,为什么它没有添加它就给我一个警告。 GCC上的当前std不应该是C ++ 11吗?为什么情况仍然如此?

那里的软件和构建系统使用默认值并期望它们保持相当稳定。每当新的标准或功能可用时,GCC不会简单地更新默认设置。

如果您需要特定版本的标准,则应明确指定。