为什么 std::future 不能在 Windows 上编译?

问题描述 投票:0回答:0

我试图在我的 Windows 11 PC 上运行这个例子

#include <future>

int main()
{
        std::future<bool> fb = std::async([]{ return false; });
        return 0;
}

我尝试使用 g++ v 6.3.0 运行它:

g++ test.cpp -o test -pthread -std=c++11

得到这个:

test.cpp: In function 'int main()':
test.cpp:5:27: error: variable 'std::future<bool> fb' has initializer but incomplete type
         std::future<bool> fb = std::async([]{ return false; });
                           ^~
test.cpp:5:62: error: invalid use of incomplete type 'class std::future<bool>'
         std::future<bool> fb = std::async([]{ return false; });
                                                              ^
In file included from test.cpp:1:0:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\future:115:11: note: declaration of 'class std::future<bool>'
     class future;
           ^~~~~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\future: At global scope:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\future:183:5: error: 'std::future<typename std::result_of<typename std::decay<_Tp>::type(typename std::decay<_BoundArgs>::type ...)>::type> std::async(_Fn&&, _Args&& ...) [with _Fn = main()::<lambda()>; _Args = {}; typename std::result_of<typename std::decay<_Tp>::type(typename std::decay<_BoundArgs>::type ...)>::type = bool]', declared using local type 'main()::<lambda()>', is used but never defined [-fpermissive]
     async(_Fn&& __fn, _Args&&... __args);
     ^~~~~

比起我用 clang v 12.0.0 尝试它并得到这个:

test.cpp:1:10: fatal error: 'future' file not found
#include <future>
         ^~~~~~~~
1 error generated.

我哪里错了,我应该修正什么?

c++ c++11 asynchronous future std-future
© www.soinside.com 2019 - 2024. All rights reserved.