'std::future<T>::wait returns compile error in msvc
Using the msvc with the /std::c++20 flag on, I can't seem to get the wait call compiled.
simple example:
#include<future>
std::future<int> fut = std::async([](){return 0;});
fut.wait();
with error:
<source>(4): error C3927: '->': trailing return type is not allowed after a non-function declarator
<source>(4): error C3484: syntax error: expected '->' before the return type
<source>(4): error C3613: missing return type after '->' ('int' assumed)
<source>(4): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<source>(4): error C2371: 'fut': redefinition; different basic types
<source>(3): note: see declaration of 'fut'
<source>(4): error C2146: syntax error: missing ';' before identifier 'wait'
compiler explorer: https://godbolt.org/z/668W7dher
What am I missing here? why doesn't this compile?
edit: As kindly pointed out by 康桓瑋 and G.M. the code was written in a filescope, which is not allowed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|