'std::array' Is Not a Member of 'std' Fix
Written November 27, 2026 · Tested with GCC 13.3.0 · 14 min read
- The error: the include is missing
- The same missing include through <iostream>: an incomplete type instead
- The fix
- Fixed size, checked access: at, front, back, fill, and std::get
Written November 27, 2026
Tested with GCC 13.3.0
What this guide is
std::array is a class template defined in the header <array>. It is a container that encapsulates a fixed size array: an aggregate type with the same semantics as a struct holding a C-style array as its only non-static data member, except that it does not decay to a pointer automatically, and it knows its own size. The number of elements is part of the type and never changes at run time.
Because the class template lives in one specific header, a missing #include <array> is the cause behind this error — but GCC words it two ways, and which one you get depends on what else the file includes:
- If nothing included has declared the name at all, the error is
'array' is not a member of 'std', and GCC's note names the header:'std::array' is defined in header '<array>'; did you forget to '#include <array>'? - If a header in the include chain has forward-declared
std::arraywithout defining it —<iostream>does this, through<tuple>— the same missing include surfaces instead as an incomplete-type error, with no note naming<array>.
Both wordings are reproduced below, exactly as GCC 13.3.0 prints them. The fix is the same for both: add <array>.
The error: the include is missing
This program declares a std::array, fills it from a braced list, and prints its size, but includes only <cstdio>:
#include <cstdio>
int main() {
std::array<int, 3> a = {1, 2, 3};
std::printf("%zu\n", a.size());
return 0;
}
$ g++ -std=c++17 cstdio.cpp -o cstdio_prog
cstdio.cpp: In function 'int main()':
cstdio.cpp:3:10: error: 'array' is not a member of 'std'
3 | std::array<int, 3> a = {1, 2, 3};
| ^~~~~
cstdio.cpp:2:1: note: 'std::array' is defined in header '<array>'; did you forget to '#include <array>'?
1 | #include <cstdio>
+++ |+#include <array>
2 | int main() {
cstdio.cpp:3:16: error: expected primary-expression before 'int'
3 | std::array<int, 3> a = {1, 2, 3};
| ^~~
cstdio.cpp:4:26: error: 'a' was not declared in this scope
4 | std::printf("%zu\n", a.size());
| ^
The two errors after the note are knock-on effects of the first one: because the declaration of std::array was never seen, the compiler cannot parse the declaration of a, and the later use of a has nothing to refer to. The same error and note appear with no includes at all and with only <cstddef> included, and the default compilation mode prints the identical error, so this shape is not a language-mode problem. Fix the first error — the missing include — and the other two disappear with it.
The same missing include through <iostream>: an incomplete type instead
Most programs that use std::array print their results, so <iostream> is usually already included — and then the error reads differently. This is the same program with <iostream> and std::cout instead of <cstdio> and std::printf:
#include <iostream>
int main() {
std::array<int, 3> a = {1, 2, 3};
std::cout << a.size() << "\n";
return 0;
}
$ g++ -std=c++17 noinclude.cpp -o noinclude_prog
noinclude.cpp: In function 'int main()':
noinclude.cpp:3:24: error: variable 'std::array<int, 3> a' has initializer but incomplete type
3 | std::array<int, 3> a = {1, 2, 3};
| ^
There is no 'array' is not a member of 'std' here and no note naming <array>, even though the defect is identical: <array> is still missing. What changed is that the <tuple> header, which <iostream> pulls in through its own include chain, forward-declares the class template — template<typename _Tp, size_t _Nm> struct array; — so the name std::array is known to the compiler, but only as an incomplete type: declared, not defined. A variable cannot be defined with an incomplete type, so that is the error GCC reports. (Declared without the braced initializer, the wording is aggregate 'std::array<int, 3> a' has incomplete type and cannot be defined — the same defect in the same family.) A forward declaration is not a definition, and it is not a rescue: the program still does not compile until <array> is added.
The neighboring headers split along the same line. Every one of them fails — none defines std::array — but the wording follows whether the include chain reaches that forward declaration:
- With no includes at all, the program fails with
'array' is not a member of 'std'and the note naming<array>. - With only
<cstdio>included, the program fails with'array' is not a member of 'std'and the note naming<array>. - With only
<cstddef>included, the program fails with'array' is not a member of 'std'and the note naming<array>. - With
<cstdio>and<algorithm>included, the program fails with'array' is not a member of 'std'and the note naming<array>. - With
<cstdio>and<utility>included, the program fails with'array' is not a member of 'std'and the note naming<array>. - With only
<iostream>included, the program fails with an incomplete-type error and no note. - With
<iostream>and<vector>included, the program fails with an incomplete-type error and no note. - With
<iostream>and<string>included, the program fails with an incomplete-type error and no note. - With
<iostream>and<algorithm>included, the program fails with an incomplete-type error and no note. - With
<iostream>and<utility>included, the program fails with an incomplete-type error and no note. - With
<iostream>and<memory>included, the program fails with an incomplete-type error and no note. - With
<iostream>and<tuple>included, the program fails with an incomplete-type error and no note. - With
<cstdio>and<vector>included, the program fails with an incomplete-type error and no note. - With
<cstdio>and<string>included, the program fails with an incomplete-type error and no note. - With
<cstdio>and<memory>included, the program fails with an incomplete-type error and no note. - With
<cstdio>and<tuple>included, the program fails with an incomplete-type error and no note. - With
<iostream>,<vector>, and<string>included together, the program fails with an incomplete-type error and no note. - With
<cstdio>,<vector>, and<algorithm>included together, the program fails with an incomplete-type error and no note.
Two of those are worth pausing on. <tuple> is the header carrying the forward declaration itself, and it still does not rescue the program — a declaration that a type exists is not the definition that gives it elements, a size, and member functions. And <vector>, the closest relative std::array has among the sequence containers, pulls the forward declaration in but not the definition. None of the headers probed for this guide — <iostream>, <cstdio>, <cstddef>, <vector>, <string>, <algorithm>, <utility>, <memory>, or <tuple>, in the combinations listed above — rescues this program on GCC 13.3.0; a different header pulling <array> in as a side effect is not a rescue to rely on. No standard header is required to define std::array on behalf of <array>, and a program that compiled only because some other header happened to pull the definition in as a side effect could break under a different library version. Include <array> in every file that names std::array.
The fix
Add the header:
#include <array>
#include <iostream>
int main() {
std::array<int, 3> a = {1, 2, 3};
std::cout << a.size() << "\n";
std::cout << a[1] << "\n";
return 0;
}
$ g++ -std=c++17 good.cpp -o good_prog
$ ./good_prog
3
2
The same program also compiles and runs with no -std flag at all. The array holds three elements, so size prints 3, and the element at index 1 prints 2. One include, <array>, defines the class template.
Fixed size, checked access: at, front, back, fill, and std::get
The size of a std::array is fixed by its type — there is no operation that grows or shrinks it — and element access comes in checked and unchecked forms. at accesses an element with bounds checking, operator[] accesses one without a required check, front and back access the first and last elements, fill assigns one value to every element, and std::get accesses an element by a compile-time index, the tuple-style access the type also supports:
#include <array>
#include <iostream>
int main() {
std::array<int, 4> a = {10, 20, 30, 40};
std::cout << a.size() << "\n";
std::cout << a.at(2) << "\n";
std::cout << a.front() << "\n";
std::cout << a.back() << "\n";
a.fill(7);
for (int v : a) {
std::cout << v << "\n";
}
std::cout << std::get<1>(a) << "\n";
return 0;
}
$ g++ -std=c++17 behavior.cpp -o behavior_prog
$ ./behavior_prog
4
30
10
40
7
7
7
7
7
The size prints 4 — the count written in the type, std::array<int, 4>. at(2) prints 30, front prints 10, and back prints 40. After fill(7) every element is 7, so iteration prints 7 four times, and std::get<1> reads the second element back as 7. The bounds check in at is the difference from operator[]: an index that is not less than the size makes at throw std::out_of_range, and uncaught, that ends the program:
#include <array>
#include <iostream>
int main() {
std::array<int, 3> a = {1, 2, 3};
std::cout << a.at(5) << "\n";
return 0;
}
$ g++ -std=c++17 at_throw.cpp -o at_throw_prog
$ ./at_throw_prog
terminate called after throwing an instance of 'std::out_of_range'
what(): array::at: __n (which is 5) >= _Nm (which is 3)
Index 5 in a three-element array is out of range, so at throws, nothing catches the exception, and the program terminates by abort instead of printing a value. The what() text is this library's own wording for the failure — the index that was asked for, 5, against the size in the type, 3.
The neighboring error: std::to_array is C++20, in the same header
std::to_array is the creation function in the same header <array>: it creates a std::array from a built-in array or a braced list, counting the elements for you. Its 'not a member' failure looks like this guide's error but has a different cause — the include is present and the language mode is the problem, because std::to_array exists only since C++20:
#include <array>
#include <iostream>
int main() {
auto a = std::to_array<int>({1, 2, 3});
std::cout << a.size() << "\n";
return 0;
}
$ g++ -std=c++17 to_array20.cpp -o to_array17_prog
to_array20.cpp: In function 'int main()':
to_array20.cpp:4:19: error: 'to_array' is not a member of 'std'
4 | auto a = std::to_array<int>({1, 2, 3});
| ^~~~~~~~
to_array20.cpp:4:19: note: 'std::to_array' is only available from C++20 onwards
to_array20.cpp:4:28: error: expected primary-expression before 'int'
4 | auto a = std::to_array<int>({1, 2, 3});
| ^~~
to_array20.cpp:4:42: error: expected ',' or ';' before ')' token
4 | auto a = std::to_array<int>({1, 2, 3});
| ^
The note is the tell: instead of naming a header to include, it names the language version the function needs. The same source, compiled as C++20, builds and runs:
#include <array>
#include <iostream>
int main() {
auto a = std::to_array<int>({1, 2, 3});
std::cout << a.size() << "\n";
return 0;
}
$ g++ -std=c++20 to_array20.cpp -o to_array20_prog
$ ./to_array20_prog
3
The counted array has three elements, so size prints 3. If the build is pinned to C++17, the other way to have the compiler count the elements is the deduction guide std::array has had since C++17: std::array a = {1, 2, 3}; compiles under -std=c++17 with the element type and size deduced from the values, and its size likewise prints 3. Read the note before reaching for an include: a note naming a header means the include is missing, and a note naming a standard version means the mode is wrong.
A different wording: array without the std::
Calling the class without its namespace qualifier is a different defect, and GCC words it differently:
#include <array>
#include <iostream>
int main() {
array<int, 3> a = {1, 2, 3};
std::cout << a.size() << "\n";
return 0;
}
$ g++ -std=c++17 unqualified.cpp -o unqualified_prog
unqualified.cpp: In function 'int main()':
unqualified.cpp:4:5: error: 'array' was not declared in this scope; did you mean 'std::array'?
4 | array<int, 3> a = {1, 2, 3};
| ^~~~~
| std::array
In file included from unqualified.cpp:1:
/usr/include/c++/13/array:94:12: note: 'std::array' declared here
94 | struct array
| ^~~~~
unqualified.cpp:4:11: error: expected primary-expression before 'int'
4 | array<int, 3> a = {1, 2, 3};
| ^~~
unqualified.cpp:5:18: error: 'a' was not declared in this scope
5 | std::cout << a.size() << "\n";
| ^
'array' was not declared in this scope is the 'has not been declared' family for this topic: an unqualified name that lookup cannot find at all. This program already includes <array>, so the include is not the problem — the declaration it adds is std::array, inside namespace std, and the use must be qualified as std::array, or the file must bring the name in deliberately. GCC's error carries the suggestion inline — did you mean 'std::array'? — and its note points at the declaration itself, in the <array> header. If your error says is not a member of 'std', the name was qualified and the include is the whole problem; if it says was not declared in this scope, check the qualifier first.
The exact rule
std::arrayis defined by#include <array>; no other header is required to define it.<iostream>,<cstdio>,<cstddef>,<vector>,<string>,<algorithm>,<utility>,<memory>, and<tuple>do not definestd::arrayon GCC 13.3.0.'array' is not a member of 'std'means the<array>include is missing and no included header has declared the name; GCC's note names the header directly:'std::array' is defined in header '<array>'; did you forget to '#include <array>'?Follow the note.- An incomplete-type error on a
std::arrayvariable —has initializer but incomplete type, orhas incomplete type and cannot be defined— is the same missing include with a forward declaration in scope:<tuple>forward-declaresstd::array, and<iostream>,<string>,<vector>, and<memory>reach that declaration through their include chains. A forward declaration is not a definition; the fix is still#include <array>. - The
expected primary-expression before 'int'and'a' was not declared in this scopeerrors that follow are knock-on effects of the missing definition, not separate defects. std::to_arrayis declared by the same#include <array>but exists only since C++20: under an earlier mode its error is'to_array' is not a member of 'std'with the note'std::to_array' is only available from C++20 onwards— a language-mode problem, not an include problem.'array' was not declared in this scopefor an unqualifiedarray(...)use is a different defect: qualify the name asstd::array— the include alone does not bring the name out of namespacestd.
The fixes, ranked
- First, check the include list of the file that names
std::array. If<array>is not there, add it — that is the fix in the common case, whichever of the two wordings the error took, and it is the fix GCC's own note names when the note appears. - Second, do not chase the follow-on errors. Fix the include and recompile; the parse error and the undeclared-
aerror are consequences, not causes. - Third, if the error is an incomplete-type error, do not go looking for a second defect — it is the missing include seen through a forward declaration, and the same added include fixes it.
- Fourth, if the failing name is
std::to_arrayand its note names C++20, raise the language mode to-std=c++20or later — no include fixes a function the mode predates. - Fifth, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::arrayas well.
Which fix for which cause
#include <array>missing,std::arrayused with<cstdio>,<cstddef>,<algorithm>, or<utility>present and no forward declaration in scope: the message is'array' is not a member of 'std'with a note naming<array>— add#include <array>.#include <array>missing,std::arrayused with<iostream>,<vector>,<string>,<memory>, or<tuple>present: the message is an incomplete-type error with no note — add#include <array>.std::to_arrayused under-std=c++17with<array>included: the message is'to_array' is not a member of 'std'with a note naming C++20 — compile as C++20 or later, or use the C++17 deduction guide instead.array(...)used without thestd::qualifier: the message is'array' was not declared in this scope— qualify the name asstd::arrayand include<array>.
Checklist
- Check the include list of the file that names the array, not just the project. The include must be in that file, or in a header that file includes directly by design.
- Read the error's exact wording before fixing.
'array' is not a member of 'std'and an incomplete-type error on the variable are the same missing include in two situations;std::to_array's'not a member'error with a C++20 note is a language-mode problem instead. - When the note appears, take the fix from it. For this error GCC names the header —
'std::array' is defined in header '<array>'— so follow the note instead of guessing. - Do not rely on a neighboring header pulling
std::arrayin. None of<iostream>,<cstdio>,<cstddef>,<vector>,<string>,<algorithm>,<utility>,<memory>, or<tuple>defines it on this toolchain, and no header is required to. A forward declaration pulled in by<tuple>is not a definition. - If the array holds
std::stringvalues, that name comes from<string>— one header per name the file uses, even when a program happens to compile without it. - After the fix, confirm the program runs, not just that it compiles: the fixed programs here print
3and2for a three-element array's size and second element, and4,30,10,40,7,7,7,7, and7across the size, checked-access, and fill sequence. - If the element count is not known as a fixed number when the code is written,
std::arrayis the wrong container — that is thestd::vectorcase, in<vector>, whose size is decided at run time.
Related guides
- 'std::vector' Is Not a Member of 'std' Fix — the same missing-include shape for the run-time-sized sequence container in
<vector>, with the same note naming the header. - 'std::set' Is Not a Member of 'std' Fix — the same missing-include shape for the sorted unique-value container in
<set>, with the same note naming the header. - C++ Arrays and std::array: C Arrays, Bounds, and the Safe Replacement — the wider tour of built-in arrays and
std::array, including bounds and where the class template replaces the C-style array. - C++ STL Containers: vector, map, and set by Example — the wider tour of the containers this array belongs with, including
std::vectorandstd::set.
Sources
- cppreference,
std::array— forstd::arraybeing defined in<array>, encapsulating fixed size arrays as an aggregate type with the semantics of a struct holding a C-style array, not decaying to a pointer automatically, andat,operator[],front,back,size, andfillbeing its element-access, capacity, and operation members. - cppreference, Standard library header
<array>— for<array>declaring thestd::arrayclass template and thestd::getandstd::to_arrayfunction templates. - cppreference,
std::to_array— forstd::to_arraybeing defined in<array>, creating astd::arrayfrom a one-dimensional built-in array, and existing since C++20. - cppreference, deduction guides for
std::array— for the deduction guide, since C++17, that deduces the element type and size of astd::arrayfrom its initial values.
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.