C++

'std::future' Is Not a Member of 'std' Fix

std::future lives in one header, <future> - and in a file that never includes it, GCC says so in a note under this error. Threading code usually sits next to <thread> and <mutex>, but neither of those headers declares it. This guide pins down when the error appears, which probed headers do and do not cause it, and the one include that fixes it by specification.

Written November 30, 2026 · Tested with GCC 13.3.0 · 12 min read

By the end of this guide
  • The error: the include is missing
  • Neighboring headers: none of them rescues it
  • The fix
  • The neighboring names: the whole header family fails too

Written November 30, 2026

Tested with GCC 13.3.0

What this guide is

std::future is a class template defined in the header <future>. It provides a mechanism to access the result of asynchronous operations: an asynchronous operation performed via std::async, std::packaged_task, or std::promise can provide a std::future object to the creator of that operation, the creator can then query, wait for, or extract a value from the future with methods such as get, and a std::future is a unique reference to the result in a shared state - use std::shared_future for non-unique access.

Because the template lives in one specific header, 'future' is not a member of 'std' has one common cause:

  • The #include <future> line is missing. For this error GCC does name the header: its note says 'std::future' is defined in header '<future>'; did you forget to '#include <future>'?, and following that note is the whole fix.

Unlike some neighboring names, no header that sits near future code rescues the program in the sweep below - not even <thread>. Each case is separated below.

The error: the include is missing

This program runs a function asynchronously with std::async and prints the value it returns through the future, but includes only <iostream>:

C++
#include <iostream>
int main() {
    std::future<int> result = std::async([] { return 42; });
    std::cout << result.get() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 a_noinclude.cpp -o a_prog
a_noinclude.cpp: In function 'int main()':
a_noinclude.cpp:3:10: error: 'future' is not a member of 'std'
    3 |     std::future<int> result = std::async([] { return 42; });
      |          ^~~~~~
a_noinclude.cpp:2:1: note: 'std::future' is defined in header '<future>'; did you forget to '#include <future>'?
    1 | #include <iostream>
  +++ |+#include <future>
    2 | int main() {
a_noinclude.cpp:3:17: error: expected primary-expression before 'int'
    3 |     std::future<int> result = std::async([] { return 42; });
      |                 ^~~
a_noinclude.cpp:3:59: error: expected primary-expression before ')' token
    3 |     std::future<int> result = std::async([] { return 42; });
      |                                                           ^
a_noinclude.cpp:4:18: error: 'result' was not declared in this scope
    4 |     std::cout << result.get() << "\n";
      |                  ^~~~~~

The first error is the defect. The expected primary-expression and 'result' was not declared in this scope errors that follow are knock-on effects: the declaration of result failed, so the template argument and every later use of result fail too. Fix the include and all of them go.

Neighboring headers: none of them rescues it

Swapping <iostream> for another nearby header changes nothing. In a sweep where each header below was compiled as the only header in a program that declares a std::future<int> and returns whether it is valid, each of these fails with the same first error, 'future' is not a member of 'std', and the same note naming <future>:

  • <thread>
  • <mutex>
  • <condition_variable>
  • <atomic>
  • <vector>
  • <string>
  • <algorithm>
  • <utility>
  • <chrono>
  • <memory>
  • <iostream>

Note <thread> and <mutex> in that list: the threading headers do not declare std::future, even though future code almost always sits in a file that also starts threads. Note <atomic> too: the rescue does not run in this direction.

The same holds when the program uses the future the way real code does. This program includes only <thread> besides <iostream>:

C++
#include <iostream>
#include <thread>
int main() {
    std::future<int> result = std::async([] { return 42; });
    std::cout << result.get() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 t_thread.cpp -o t_thread_prog
t_thread.cpp: In function 'int main()':
t_thread.cpp:4:10: error: 'future' is not a member of 'std'
    4 |     std::future<int> result = std::async([] { return 42; });
      |          ^~~~~~
t_thread.cpp:3:1: note: 'std::future' is defined in header '<future>'; did you forget to '#include <future>'?
    2 | #include <thread>
  +++ |+#include <future>
    3 | int main() {
t_thread.cpp:4:17: error: expected primary-expression before 'int'
    4 |     std::future<int> result = std::async([] { return 42; });
      |                 ^~~
t_thread.cpp:4:59: error: expected primary-expression before ')' token
    4 |     std::future<int> result = std::async([] { return 42; });
      |                                                           ^
t_thread.cpp:5:18: error: 'result' was not declared in this scope
    5 |     std::cout << result.get() << "\n";
      |                  ^~~~~~

No header in the sweep only forward-declares the template either: there is no middle outcome here where the title error disappears but the type stays incomplete. In the sweep probed here, the choice is binary - include <future> and the name is fully declared, or leave it out and the name does not exist at all. That is a property of this library version, not a rule of the language - no header except <future> is required to declare std::future, and another library could pull it in transitively. A program that uses std::future includes <future>, whether or not it happens to compile without it.

The fix

Add the header:

C++
#include <future>
#include <iostream>
int main() {
    std::future<int> result = std::async(std::launch::async, [] { return 42; });
    std::cout << result.get() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 h_fixed.cpp -o h_prog
$ ./h_prog
42

One include, <future>, declares the template. std::async runs the function asynchronously - potentially in a separate thread - and returns a std::future that eventually holds its result, and get waits for that result and returns it, so the program prints 42.

The neighboring names: the whole header family fails too

The other names declared by <future> fail with the same shape of error when it is missing. std::promise - the class template that stores a value or an exception later acquired asynchronously via a std::future created by the promise - gets its own error and its own note, and the std::future on the next line gets the title error again:

C++
#include <iostream>
int main() {
    std::promise<int> prom;
    std::future<int> result = prom.get_future();
    prom.set_value(7);
    std::cout << result.get() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 b_promise.cpp -o b_prog
b_promise.cpp: In function 'int main()':
b_promise.cpp:3:10: error: 'promise' is not a member of 'std'
    3 |     std::promise<int> prom;
      |          ^~~~~~~
b_promise.cpp:2:1: note: 'std::promise' is defined in header '<future>'; did you forget to '#include <future>'?
    1 | #include <iostream>
  +++ |+#include <future>
    2 | int main() {
b_promise.cpp:3:18: error: expected primary-expression before 'int'
    3 |     std::promise<int> prom;
      |                  ^~~
b_promise.cpp:4:10: error: 'future' is not a member of 'std'
    4 |     std::future<int> result = prom.get_future();
      |          ^~~~~~
b_promise.cpp:4:10: note: 'std::future' is defined in header '<future>'; did you forget to '#include <future>'?
b_promise.cpp:4:17: error: expected primary-expression before 'int'
    4 |     std::future<int> result = prom.get_future();
      |                 ^~~
b_promise.cpp:5:5: error: 'prom' was not declared in this scope
    5 |     prom.set_value(7);
      |     ^~~~
b_promise.cpp:6:18: error: 'result' was not declared in this scope
    6 |     std::cout << result.get() << "\n";
      |                  ^~~~~~

std::async fails the same way, with a note naming <future> for async itself - and the launch policy on the same line fails with a different wording, 'std::launch' has not been declared, and no header note:

C++
#include <iostream>
int main() {
    auto result = std::async(std::launch::async, [] { return 8; });
    std::cout << result.get() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 c_async.cpp -o c_prog
c_async.cpp: In function 'int main()':
c_async.cpp:3:24: error: 'async' is not a member of 'std'
    3 |     auto result = std::async(std::launch::async, [] { return 8; });
      |                        ^~~~~
c_async.cpp:2:1: note: 'std::async' is defined in header '<future>'; did you forget to '#include <future>'?
    1 | #include <iostream>
  +++ |+#include <future>
    2 | int main() {
c_async.cpp:3:35: error: 'std::launch' has not been declared
    3 |     auto result = std::async(std::launch::async, [] { return 8; });
      |                                   ^~~~~~

std::packaged_task - the class template that wraps any callable target so it can be invoked asynchronously, storing its return value or exception in a shared state accessed through std::future objects - fails the same way, again with its own note naming <future>:

C++
#include <iostream>
int main() {
    std::packaged_task<int()> task([] { return 9; });
    std::future<int> result = task.get_future();
    task();
    std::cout << result.get() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 d_packaged.cpp -o d_prog
d_packaged.cpp: In function 'int main()':
d_packaged.cpp:3:10: error: 'packaged_task' is not a member of 'std'
    3 |     std::packaged_task<int()> task([] { return 9; });
      |          ^~~~~~~~~~~~~
d_packaged.cpp:2:1: note: 'std::packaged_task' is defined in header '<future>'; did you forget to '#include <future>'?
    1 | #include <iostream>
  +++ |+#include <future>
    2 | int main() {
d_packaged.cpp:3:31: error: 'task' was not declared in this scope
    3 |     std::packaged_task<int()> task([] { return 9; });
      |                               ^~~~
d_packaged.cpp:4:10: error: 'future' is not a member of 'std'
    4 |     std::future<int> result = task.get_future();
      |          ^~~~~~
d_packaged.cpp:4:10: note: 'std::future' is defined in header '<future>'; did you forget to '#include <future>'?
d_packaged.cpp:4:17: error: expected primary-expression before 'int'
    4 |     std::future<int> result = task.get_future();
      |                 ^~~
d_packaged.cpp:6:18: error: 'result' was not declared in this scope
    6 |     std::cout << result.get() << "\n";
      |                  ^~~~~~

std::shared_future - the variant that allows non-unique access to the result in a shared state - fails the same way, except that GCC prints no header note under this error:

C++
#include <iostream>
int main() {
    std::shared_future<int> result;
    std::cout << result.valid() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 e_shared.cpp -o e_prog
e_shared.cpp: In function 'int main()':
e_shared.cpp:3:10: error: 'shared_future' is not a member of 'std'
    3 |     std::shared_future<int> result;
      |          ^~~~~~~~~~~~~
e_shared.cpp:3:24: error: expected primary-expression before 'int'
    3 |     std::shared_future<int> result;
      |                        ^~~
e_shared.cpp:4:18: error: 'result' was not declared in this scope
    4 |     std::cout << result.valid() << "\n";
      |                  ^~~~~~

And std::launch - the enumeration that specifies the launch policy for std::async - is declared by <future> as well, and fails the same way, again with no header note from GCC:

C++
#include <iostream>
int main() {
    std::launch policy = std::launch::async;
    std::cout << static_cast<int>(policy) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 f_launch.cpp -o f_prog
f_launch.cpp: In function 'int main()':
f_launch.cpp:3:10: error: 'launch' is not a member of 'std'
    3 |     std::launch policy = std::launch::async;
      |          ^~~~~~
f_launch.cpp:4:35: error: 'policy' was not declared in this scope
    4 |     std::cout << static_cast<int>(policy) << "\n";
      |                                   ^~~~~~

One added include declares every one of these names: the future, the promise, the async function, the packaged task, the shared future, and the launch policy.

The neighboring names, fixed

With <future> added, the promise, the packaged task, the shared future, and the deferred launch policy all work in short programs. The promise's set_value stores the value in the shared state, and the future obtained from get_future retrieves it:

C++
#include <future>
#include <iostream>
int main() {
    std::promise<int> prom;
    std::future<int> result = prom.get_future();
    prom.set_value(7);
    std::cout << result.get() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 i_promise_fixed.cpp -o i_prog
$ ./i_prog
7

The packaged task wraps the lambda, get_future returns the future associated with its result, and invoking the task stores the return value for that future to read:

C++
#include <future>
#include <iostream>
int main() {
    std::packaged_task<int()> task([] { return 9; });
    std::future<int> result = task.get_future();
    task();
    std::cout << result.get() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 j_packaged_fixed.cpp -o j_prog
$ ./j_prog
9

A std::shared_future obtained by calling share on a future can be read more than once - unlike the unique future it came from, it prints the value on both get calls:

C++
#include <future>
#include <iostream>
int main() {
    std::future<int> base = std::async([] { return 5; });
    std::shared_future<int> shared = base.share();
    std::cout << shared.get() << "\n";
    std::cout << shared.get() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_shared_fixed.cpp -o k_prog
$ ./k_prog
5
5

And a std::launch::deferred policy stores the call for lazy evaluation, performed when a waiting function such as get is first called on the returned future:

C++
#include <future>
#include <iostream>
int main() {
    std::future<int> result = std::async(std::launch::deferred, [] { return 11; });
    std::cout << result.get() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 l_launch_fixed.cpp -o l_prog
$ ./l_prog
11

A different wording: the name without its qualifier

Including <future> is not the only half of the name. This program includes the header but drops the std:: qualifier:

C++
#include <future>
#include <iostream>
int main() {
    future<int> result = std::async([] { return 42; });
    std::cout << result.get() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 g_unqualified.cpp -o g_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:4:5: error: 'future' was not declared in this scope; did you mean 'std::future'?
    4 |     future<int> result = std::async([] { return 42; });
      |     ^~~~~~
      |     std::future
In file included from g_unqualified.cpp:1:
/usr/include/c++/13/future:137:11: note: 'std::future' declared here
  137 |     class future;
      |           ^~~~~~
g_unqualified.cpp:4:12: error: expected primary-expression before 'int'
    4 |     future<int> result = std::async([] { return 42; });
      |            ^~~
g_unqualified.cpp:4:54: error: expected primary-expression before ')' token
    4 |     future<int> result = std::async([] { return 42; });
      |                                                      ^
g_unqualified.cpp:5:18: error: 'result' was not declared in this scope
    5 |     std::cout << result.get() << "\n";
      |                  ^~~~~~

That wording - was not declared in this scope - is a different defect with a different fix: the header is present, the qualifier is not. Qualify the name as std::future; adding includes does not bring the name out of namespace std.

The exact rule

  • std::future is declared by #include <future>, and nowhere else by rule. In the sweep probed here, <thread>, <mutex>, <condition_variable>, <atomic>, <vector>, <string>, <algorithm>, <utility>, <chrono>, <memory>, and <iostream> do not declare it.
  • 'future' is not a member of 'std' means the <future> include is missing, and GCC's note names the header directly: 'std::future' is defined in header '<future>'. Follow the note.
  • In the sweep probed here, no neighboring header rescues std::future transitively and none forward-declares it: there is no header in the sweep whose presence makes the program compile without <future>, and none that makes only the title error disappear.
  • std::promise, std::async, std::packaged_task, std::shared_future, and std::launch are declared by the same #include <future>: in the programs shown here, which include only <iostream> beside the use, each gets its own is not a member of 'std' error when that include is missing - with a header note for future, promise, async, and packaged_task, and without one for shared_future and launch.
  • 'future' was not declared in this scope for an unqualified future use is a different defect: qualify the name as std::future - the include alone does not bring the name out of namespace std.
  • The expected primary-expression and was not declared in this scope errors that follow a failed declaration are knock-on effects of the missing declaration, not separate defects.

The fixes, ranked

  • First, check the include list of the file that names std::future. If <future> is not there, add it - that is the fix in the common case, and it is the fix GCC's own note names.
  • Second, do not chase the follow-on errors. Fix the include and recompile; the undeclared-result and expected-expression errors are consequences, not causes.
  • Third, do not expect <thread>, <mutex>, or any other neighboring header to supply the name. In the sweep here none of them does - a file that uses std::future includes <future> itself.
  • Fourth, if the error says was not declared in this scope instead, fix the name's qualifier to std::future as well.
  • Fifth, if the failing name is a neighboring one - promise, async, packaged_task, shared_future, or launch - the same added include fixes it: every one of those names shares the header. Two of them, shared_future and launch, get no note in the programs here; the fix is the same header.

Which fix for which cause

  • #include <future> missing, std::future used with <iostream> present: the message is 'future' is not a member of 'std' - add #include <future>.
  • Only a header from the sweep included - <thread>, <mutex>, <condition_variable>, <atomic>, <vector>, <string>, <algorithm>, <utility>, <chrono>, <memory>, or <iostream>: same message, same note - add #include <future>.
  • std::promise, std::async, or std::packaged_task used without <future>: the message names that name, with a note naming <future> - add #include <future>.
  • std::shared_future or std::launch used without <future>: the message names that name, with no header note from GCC - add #include <future>.
  • std::async used with a launch policy and without <future>: async gets the is not a member of 'std' error and note, and std::launch on the same line gets 'std::launch' has not been declared - add #include <future>.
  • future used without the std:: qualifier, <future> included: the message is 'future' was not declared in this scope - qualify the name as std::future.

Checklist

  • Check the include list of the file that names the future, not just the project. The include must be in that file, or in a header that file includes directly by design.
  • Read the note under the error. For this error GCC names the header - 'std::future' is defined in header '<future>' - so take the fix from the note instead of guessing. Two neighboring names, shared_future and launch, get no note in the programs here; the fix is the same header.
  • Do not rely on a neighboring header pulling std::future in. In the sweep here, none of the eleven probed headers does, and no header is required to.
  • One header per name the file uses: std::thread comes from <thread> and std::mutex from <mutex>, even in a program whose subject is the future - and neither of those headers declares std::future in return.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print 42 for the async result, 7 for the promise value, 9 for the packaged task, 5 and 5 across the two shared-future reads, and 11 for the deferred call.
  • 'std::atomic' Is Not a Member of 'std' Fix - the same missing-include shape for the atomic template in <atomic>; in that direction <future> does pull the other header in, while <atomic> does not rescue the future in return.
  • 'std::thread' Is Not a Member of 'std' Fix - the same missing-include shape for the thread class in <thread>, the header that does not rescue the future even though the two usually appear in the same file.

Sources

  • cppreference, std::future - for std::future being a class template defined in <future> (since C++11) that provides a mechanism to access the result of asynchronous operations performed via std::async, std::packaged_task, or std::promise, with get returning the result, and a future being a unique reference to the result in a shared state, with std::shared_future for non-unique access.
  • cppreference, Standard library header <future> - for <future> declaring std::promise, std::packaged_task, std::future, and std::shared_future (all since C++11), the std::launch and std::future_status enumerations, and the std::async function template.
  • cppreference, std::promise - for std::promise being a class template defined in <future> (since C++11) that stores a value or an exception later acquired asynchronously via a std::future created by the promise, with get_future returning that future and set_value setting the result.
  • cppreference, std::async - for std::async being defined in <future> (since C++11), running a function asynchronously (potentially in a separate thread) and returning a std::future that will eventually hold the result, with std::launch::async and std::launch::deferred as the launch policies and deferred invocation performed lazily on the first waiting call.
  • cppreference, std::packaged_task - for std::packaged_task being a class template defined in <future> (since C++11) that wraps any callable target so it can be invoked asynchronously, storing its return value or exception in a shared state accessed through std::future objects, with get_future returning the associated future.

Keep Exploring