C++
'std::list' Is Not a Member of 'std' Fix
std::list lives in one header, <list>, and has since C++98 - there is no language-mode half to this error. Miss the header and the name is not a member of std, with a note naming the header to add; include it and the same program compiles in every standard mode. Among the headers probed in this guide's sweep, none rescues the name at all: the title error stays exactly as it was.
Written November 29, 2026 · Tested with GCC 13.3.0 · 16 min read
- The rule underneath: one header, any standard mode
- The failure: no <list> include
- The same failure at namespace scope: does not name a template type
- No older-mode shape: <list> included compiles at C++98
Written November 29, 2026
Tested with GCC 13.3.0
What this guide is
The error on a std::list name means the compiler has no list name inside std to find. Inside a function, GCC words it exactly as this guide's title promises: 'list' is not a member of 'std'. The cause is a missing include: nothing in the file included <list>, the header that declares the name, so the lookup fails at the first use. For this name that is the whole story - there is no second shape. std::list dates from C++98, the first standard, so no language mode is too old for it: with the header included, the same program compiles at -std=c++98 and at -std=c++11 alike, as the included-header section below shows. When a std::list program fails with this error, the mode is never the fault; the include is.
The wording changes with where the failing name sits. At namespace scope, where the name is used as a type for a variable declaration, GCC reports 'list' in namespace 'std' does not name a template type instead - note the word "template": this name is a class template, and the namespace-scope wording says so, where the same fault on a non-template name is worded as "does not name a type". Both wordings appear below; they are one fault - the name is absent - read at two different positions in the file.
This error also carries its remedy with it: GCC attaches a note to the std::list error naming the header to add - 'std::list' is defined in header '<list>'; did you forget to '#include <list>'? Read the note before anything else in the cascade, because it is the diagnosis and the fix in one line. And among the headers probed in the sweep below, no neighboring header rescues this name at all - not even <deque>, the neighboring sequence container: the title error persists unchanged in every sweep program. The fix stays direct: #include <list> in the file itself.
The rule underneath: one header, any standard mode
The std::list page defines the type: list is a container that supports constant time insertion and removal of elements from anywhere in the container, is usually implemented as a doubly-linked list, and - the sentence both neighboring-error sections below rest on - fast random access is not supported. The page's own history reaches back to C++98: its defect reports are applied to C++98, and the class template carries no later-standard date of its own (the dates on the page belong to later additions around it, such as the pmr alias since C++17). Its member list gives the operations this guide's programs use: front accesses the first element, back the last element, push_back adds an element to the end, push_front inserts an element at the beginning, size returns the number of elements, and sort sorts the elements - a member function, which matters below.
The header page
shows what the header declares, in namespace std: the list class template - described there as the doubly-linked list - and its comparison and swap functions. So a std::list name needs exactly one condition: the header included, so the declarations are in the file. No mode condition stands next to it.
The failure: no <list> include
This program uses std::list<int> and includes no header at all - deliberately, because a companion header would be its own possible rescue, and the sweep below measures each candidate header on its own instead:
int main() {
std::list<int> xs;
xs.push_back(10);
return xs.front() == 10 ? 0 : 1;
}
$ g++ -std=c++11 p1_fail_no_include.cpp -o p1_fail_no_include
p1_fail_no_include.cpp: In function 'int main()':
p1_fail_no_include.cpp:2:10: error: 'list' is not a member of 'std'
2 | std::list<int> xs;
| ^~~~
p1_fail_no_include.cpp:1:1: note: 'std::list' is defined in header '<list>'; did you forget to '#include <list>'?
+++ |+#include <list>
1 | int main() {
p1_fail_no_include.cpp:2:15: error: expected primary-expression before 'int'
2 | std::list<int> xs;
| ^~~
p1_fail_no_include.cpp:3:5: error: 'xs' was not declared in this scope
3 | xs.push_back(10);
| ^~
Read the note first: it sits directly under the title error and names the header, so this shape diagnoses itself - the include is missing, and the note says which one. The errors that follow are the cascade from that one absence. expected primary-expression before 'int' is the compiler trying to read std::list<int> as something other than a template name, because the template name is not there. And 'xs' was not declared in this scope is fallout: the declaration failed, so the variable does not exist where it is used on the next line.
The same failure at namespace scope: does not name a template type
The same missing include at namespace scope is worded differently. This program declares the list as a file-scope variable, still with no header:
std::list<int> g_xs;
int main() {
g_xs.push_back(10);
return g_xs.front() == 10 ? 0 : 1;
}
$ g++ -std=c++11 p1b_fail_scope.cpp -o p1b_fail_scope
p1b_fail_scope.cpp:1:6: error: 'list' in namespace 'std' does not name a template type
1 | std::list<int> g_xs;
| ^~~~
p1b_fail_scope.cpp:1:1: note: 'std::list' is defined in header '<list>'; did you forget to '#include <list>'?
+++ |+#include <list>
1 | std::list<int> g_xs;
p1b_fail_scope.cpp: In function 'int main()':
p1b_fail_scope.cpp:4:5: error: 'g_xs' was not declared in this scope
4 | g_xs.push_back(10);
| ^~~~
Same fault, different first line: where the name is used as a type outside a function, GCC says it does not name a template type; where it is used inside a function, GCC says it is not a member of std. The wording is worth recognizing exactly, because "does not name a template type" is this name's namespace-scope form - a non-template name in the same position is reported as "does not name a type", without the word "template". The header note appears here too, unchanged, naming <list> as the remedy, and the undeclared-variable error follows inside main exactly as in the function-scope shape. Recognize either wording as the missing-include shape.
No older-mode shape: <list> included compiles at C++98
Names that arrived in a later standard have a second failure shape - header included, mode too old - and guides for those names show a #error from inside the library headers as its first diagnostic. This name has no such shape, and the honest way to show that is to compile the included program in the oldest mode: it succeeds. This program includes <list>, pushes two values, and prints both ends:
#include <list>
#include <iostream>
int main() {
std::list<int> xs;
xs.push_back(10);
xs.push_back(20);
std::cout << xs.front() << " " << xs.back() << "\n";
return 0;
}
$ g++ -std=c++98 p2_included.cpp -o p2_cpp98
$ ./p2_cpp98
10 20
$ g++ -std=c++11 p2_included.cpp -o p2_cpp11
$ ./p2_cpp11
10 20
No diagnostics in either mode, and the same output, 10 20, from both binaries: the front of the list is the first value pushed and the back is the second. So if a std::list program shows the title error, do not reach for the compile line - there is no mode in which <list> refuses to declare the name, and no "only available from" note exists for it. The missing include is the only shape this error takes, which makes the diagnosis shorter than for the later-standard names: read the header note, add the include, and the error is gone.
The header sweep: no rescue among the headers probed
A missing standard name is sometimes rescued by accident, when another header happens to include the one that declares it. For std::list the sweep in this guide finds no rescue at all among the headers probed. Each sweep program uses the list with one candidate header as its only include, and no other header - a second include would be its own possible rescue and would spoil the measurement. This program, with <string> in that position and still no <list>, fails with exactly the missing-include shape:
#include <string>
int main() {
std::list<int> xs;
xs.push_back(10);
return xs.front() == 10 ? 0 : 1;
}
$ g++ -std=c++11 sweep_string.cpp -o sweep_string
sweep_string.cpp: In function 'int main()':
sweep_string.cpp:4:10: error: 'list' is not a member of 'std'
4 | std::list<int> xs;
| ^~~~
sweep_string.cpp:2:1: note: 'std::list' is defined in header '<list>'; did you forget to '#include <list>'?
1 | #include <string>
+++ |+#include <list>
2 |
sweep_string.cpp:4:15: error: expected primary-expression before 'int'
4 | std::list<int> xs;
| ^~~
sweep_string.cpp:5:5: error: 'xs' was not declared in this scope
5 | xs.push_back(10);
| ^~
Read what did not change. The title error is still there, word for word: the compiler still says list is not a member of std, still attaches the same header note naming <list>, and the same cascade follows. In the sweep above, no candidate header declared the name, even as a forward declaration - so there is no half-rescued incomplete-type state for this name among the headers probed, unlike names where a probed neighbor declares without defining. The same program was compiled with each of <iostream>, <vector>, <deque>, <algorithm> and <utility> as the only candidate header, at C++11: every one fails with the same title error, the same header note, and the same cascade shape. The <deque> result is the one worth pausing on: a deque is the neighboring sequence container, the header a reader would most expect to leak this one - and it does not. So of the six headers probed in place of <list>, all six leave the title error in place and none produces a working program - among the headers probed, the name simply does not arrive by accident. That makes the repair the direct one: include <list> itself in every file that names std::list.
The fix: include <list>
The header included, and the library is fully usable in any standard mode. This program builds a list with push_back and push_front, reads the two ends back with front() and back(), and prints the list's size:
#include <list>
#include <iostream>
int main() {
std::list<int> xs;
xs.push_back(20);
xs.push_front(10);
xs.push_back(30);
std::cout << xs.front() << " " << xs.back() << "\n";
std::cout << "size " << xs.size() << "\n";
return 0;
}
$ g++ -std=c++11 p4_fix.cpp -o p4_fix
$ ./p4_fix
10 30
size 3
Every name that failed before now resolves. The list is built in three steps: push_back(20) puts 20 in an empty list, push_front(10) puts 10 ahead of it, and push_back(30) appends 30 at the end - so the front of the list is 10 and the back is 30, which is what the first line prints. The second line is the size: the list holds 3 elements, matching the three insertions. A list keeps its elements in insertion-linked order - front to back is the order the pushes built - so every printed value here is fully determined by the values in the program, and any other output means the program, not the machine, differs.
Neighboring error: subscripting a list
Once <list> is included, a different error appears when the list is read the way a vector is read. A list supports no fast random access, so it has no subscript operator - xs[1] fails like this:
#include <list>
int main() {
std::list<int> xs{10, 20, 30};
return xs[1] == 20 ? 0 : 1;
}
$ g++ -std=c++11 p5_neighbour_subscript.cpp -o p5_neighbour_subscript
p5_neighbour_subscript.cpp: In function 'int main()':
p5_neighbour_subscript.cpp:5:14: error: no match for 'operator[]' (operand types are 'std::__cxx11::list<int>' and 'int')
5 | return xs[1] == 20 ? 0 : 1;
| ^
The contrast separates the two errors cleanly. This error says nothing about a missing name - the include is already right, the type was found, and the failure is the access itself: there is no operator[] on a list to match the call. The title error names list as not a member of std, because the type was never there to be used. The repair here is to change the access, not the include: walk the list with an iterator - auto it = xs.begin(); std::advance(it, 1); reaches the second element - or, if subscript access is the program's real shape, use a container that provides it, such as std::vector or std::deque. Numbered access is the one thing this container does not offer.
Neighboring error: std::sort on a list
The other neighboring fault also keeps the right include and reaches for the generic algorithm instead of the member the container provides. std::sort requires random access iterators, and a list's iterators are bidirectional - they step forward and backward but cannot jump - so sorting a list with the free function fails inside the algorithm headers:
#include <list>
#include <algorithm>
int main() {
std::list<int> xs{30, 10, 20};
std::sort(xs.begin(), xs.end());
return xs.front() == 10 ? 0 : 1;
}
$ g++ -std=c++11 p6_neighbour_std_sort.cpp -o p6_neighbour_std_sort
In file included from /usr/include/c++/13/algorithm:61,
from p6_neighbour_std_sort.cpp:2:
/usr/include/c++/13/bits/stl_algo.h: In instantiation of 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = _List_iterator<int>; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/13/bits/stl_algo.h:4861:18: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = _List_iterator<int>]'
p6_neighbour_std_sort.cpp:6:14: required from here
/usr/include/c++/13/bits/stl_algo.h:1948:50: error: no match for 'operator-' (operand types are 'std::_List_iterator<int>' and 'std::_List_iterator<int>')
1948 | std::__lg(__last - __first) * 2,
| ~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/13/bits/stl_algobase.h:67,
from /usr/include/c++/13/list:62,
from p6_neighbour_std_sort.cpp:1:
/usr/include/c++/13/bits/stl_iterator.h:625:5: note: candidate: 'template<class _IteratorL, class _IteratorR> decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
625 | operator-(const reverse_iterator<_IteratorL>& __x,
| ^~~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:625:5: note: template argument deduction/substitution failed:
/usr/include/c++/13/bits/stl_algo.h:1948:50: note: 'std::_List_iterator<int>' is not derived from 'const std::reverse_iterator<_Iterator>'
1948 | std::__lg(__last - __first) * 2,
| ~~~~~~~^~~~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:1800:5: note: candidate: 'template<class _IteratorL, class _IteratorR> decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
1800 | operator-(const move_iterator<_IteratorL>& __x,
| ^~~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:1800:5: note: template argument deduction/substitution failed:
/usr/include/c++/13/bits/stl_algo.h:1948:50: note: 'std::_List_iterator<int>' is not derived from 'const std::move_iterator<_IteratorL>'
1948 | std::__lg(__last - __first) * 2,
| ~~~~~~~^~~~~~~~~
Nothing in this outcome says a name is missing - the include is right, the list was built, and the failure is the algorithm's requirement, not the container's name. The line to recognize is the one marked error:: no match for 'operator-' on two list iterators, inside bits/stl_algo.h, where the sort implementation tries to subtract one iterator from the other to measure the range - arithmetic a bidirectional iterator does not provide. The instantiation lines above it name the mismatch directly: _RandomAccessIterator bound to _List_iterator<int>. The repair is the member function: xs.sort() sorts the list in place, works with the iterators the list actually has, and invalidates nothing. When a sort of a list fails with iterator arithmetic errors from inside the algorithm headers, read it as the wrong sort - the container carries its own.
Decision summary
- The first errors are
'list' is not a member of 'std', with a note under it saying'std::list' is defined in header '<list>'; did you forget to '#include <list>'?: the header is missing - add#include <list>, exactly as the note says; every later error in the cascade traces to the absent name. - The first error is
'list' in namespace 'std' does not name a template type, with the same header note under it: the same missing include, read at namespace scope where the name is used as a type - add<list>the same way. - The file already includes
<list>and the program still fails: it is not this error and not a language-mode problem - with the header included, the same program compiles and runs at-std=c++98and at-std=c++11;std::listhas no older-mode shape, so read the actual first error instead of changing the compile line. - The error is still the title error even though the file includes some other header: in the sweep above, each of
<string>,<iostream>,<vector>,<deque>,<algorithm>and<utility>in place of<list>left the title error in place - among the headers probed, none declares this name by accident, so a neighboring include is not a state to reason about for this name; add<list>itself. - The error instead is
no match for 'operator[]'with the list as an operand: the type was found and the access form is wrong for this container - a list has no subscript operator, because fast random access is not supported; walk an iterator withstd::advance, or use a container that provides subscript access. - The failure is
no match for 'operator-'on list iterators from inside the algorithm headers, in an instantiation ofstd::sort: the include is right and the algorithm is wrong for this container -std::sortrequires random access iterators; call the memberxs.sort()instead.
Checklist
- The file includes
<list>itself - not a neighboring header in its place; in the sweep above, each of the six probed headers left the title error in place, so none of them stands in for<list>. - No language-mode change is part of this fix:
std::listdates from C++98, and with<list>included the program compiles in the oldest mode as well as the newest - if the title error appears, the include is the fault, never the mode. - The first error is read before the cascade: the
expected primary-expressionand'was not declared in this scope'errors disappear when the name error at the top is fixed. - Elements are reached by iterator,
front()orback()- never by subscript: a list has nooperator[], because fast random access is not supported. - A list is sorted with its member
sort()- neverstd::sort, which requires random access iterators and fails on a list's bidirectional iterators inside the algorithm headers. - The fixed program compiles, runs, and prints
10 30andsize 3, in order.
Related guides
- 'std::deque' Is Not a Member of 'std' Fix - the same missing-name fault on the neighboring sequence container:
std::dequelives in<deque>wherestd::listlives in<list>- and the sweep above puts the two side by side, because<deque>in place of<list>did not rescue this name. - 'std::vector' Is Not a Member of 'std' Fix - the same missing-name fault on the random-access sequence container: the container to switch to when a program's real shape is subscript access, which a list does not provide.
- 'std::unordered_map' Is Not a Member of 'std' Fix - the same missing-name fault with the opposite mode story: that name arrived in C++11 and has a genuine older-mode shape with a
#errorfrom inside the library headers, wherestd::list, present since C++98, has none.
Sources
- cppreference.com, std::list — the type at the center of the error: the class template
listdefined in header<list>, a container supporting constant time insertion and removal from anywhere, usually implemented as a doubly-linked list, with fast random access not supported - the property behind both neighboring errors - and its member list givingfront,back,push_back,push_front,sizeand the membersort, the operations the fix and repair programs use. - cppreference.com, Standard library header
listclass template, described as the doubly-linked list, and its comparison andswapfunctions, in namespacestd- the declarations a file gets by including<list>itself; in the sweep above, no probed neighbor brought them in. - cppreference.com, std::list::sort — the member sort the std::sort neighboring error should switch to: it sorts the elements, preserves the order of equivalent elements and invalidates no iterators or references, and its notes state that
std::sortrequires random access iterators and so cannot be used withlist- the rule the neighboring error enforces.
Keep Exploring
Seven tips and seven puzzles so far, each one a short runnable example with the fix explained.
Paste an AddressSanitizer, UBSan, or ThreadSanitizer report and get the bug, the file and line, and the fix \u2014 in plain language.
C++20 and C++23 features, migration paths, and measured trade-offs.
The full C++ hub \u2014 language basics, the standard library, coroutines, and measured comparisons.
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.