C++
'std::priority_queue' Is Not a Member of 'std' Fix
std::priority_queue lives in one header, <queue>, 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 - not even <vector>, the container the adapter uses by default, or <deque>, the other standard container it can use: holding the elements is the container's job, and declaring the adapter is <queue>'s.
Written November 29, 2026 · Tested with GCC 13.3.0 · 16 min read
- The rule underneath: one header, any standard mode
- The failure: no <queue> include
- The same failure at namespace scope: does not name a template type
- No older-mode shape: <queue> included compiles at C++98
Written November 29, 2026
Tested with GCC 13.3.0
What this guide is
The error on a std::priority_queue name means the compiler has no priority_queue name inside std to find. Inside a function, GCC words it exactly as this guide's title promises: 'priority_queue' is not a member of 'std'. The cause is a missing include: nothing in the file included <queue>, 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::priority_queue 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::priority_queue 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 'priority_queue' 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::priority_queue error naming the header to add - 'std::priority_queue' is defined in header '<queue>'; did you forget to '#include <queue>'? 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 <vector>, the container the adapter holds its elements in by default, because a container the adapter can use is not the adapter itself. The fix stays direct: #include <queue> in the file itself.
The rule underneath: one header, any standard mode
The std::priority_queue page defines the type: a priority queue is a container adapter that provides constant time lookup of the largest (by default) element, at the expense of logarithmic insertion and extraction. It takes three template parameters: the element type, the underlying container used to store the elements - std::vector by default, with std::deque also meeting the container's requirements - and a comparison type providing a strict weak ordering, std::less by default, which is what puts the largest element on top. A user-provided comparison can change the ordering: using std::greater makes the smallest element appear as the top() instead, as the last program in this guide shows. Its member list gives the operations this guide's programs use: top accesses the top element, push inserts an element and sorts the underlying container, pop removes the top element, and empty and size report the capacity state. That member list is also the whole interface: there is no front, no back, and no iterator access on it, which is what the two neighboring errors below run into.
The std: two class templates, queue - which adapts a container to provide a first-in, first-out queue - and priority_queue, which adapts a container to provide a priority queue, plus the comparison operators for queue and the std::swap overloads for both adapters. So a std::priority_queue 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 <queue> include
This program uses std::priority_queue<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::priority_queue<int> pq;
pq.push(3);
return pq.top() == 3 ? 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: 'priority_queue' is not a member of 'std'
2 | std::priority_queue<int> pq;
| ^~~~~~~~~~~~~~
p1_fail_no_include.cpp:1:1: note: 'std::priority_queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
+++ |+#include <queue>
1 | int main() {
p1_fail_no_include.cpp:2:25: error: expected primary-expression before 'int'
2 | std::priority_queue<int> pq;
| ^~~
p1_fail_no_include.cpp:3:5: error: 'pq' was not declared in this scope
3 | pq.push(3);
| ^~
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', pointed at the template argument the compiler can no longer read as part of a type, and 'pq' was not declared in this scope, because the declaration failed and 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 priority queue as a file-scope variable, still with no header:
std::priority_queue<int> g_pq;
int main() {
g_pq.push(3);
return g_pq.top() == 3 ? 0 : 1;
}
$ g++ -std=c++11 p1b_fail_scope.cpp -o p1b_fail_scope
p1b_fail_scope.cpp:1:6: error: 'priority_queue' in namespace 'std' does not name a template type
1 | std::priority_queue<int> g_pq;
| ^~~~~~~~~~~~~~
p1b_fail_scope.cpp:1:1: note: 'std::priority_queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
+++ |+#include <queue>
1 | std::priority_queue<int> g_pq;
p1b_fail_scope.cpp: In function 'int main()':
p1b_fail_scope.cpp:4:5: error: 'g_pq' was not declared in this scope
4 | g_pq.push(3);
| ^~~~
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 <queue> 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: <queue> 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 <queue>, pushes three values, and prints the top element and the size:
#include <iostream>
#include <queue>
int main() {
std::priority_queue<int> pq;
pq.push(3);
pq.push(1);
pq.push(4);
std::cout << pq.top() << " " << pq.size() << "\n";
return 0;
}
$ g++ -std=c++98 p2_included.cpp -o p2_cpp98
$ ./p2_cpp98
4 3
$ g++ -std=c++11 p2_included.cpp -o p2_cpp11
$ ./p2_cpp11
4 3
No diagnostics in either mode, and the same output, 4 3, from both binaries: of the values 3, 1 and 4 pushed in that order, the largest, 4, sits on top - a priority queue does not hand its elements back in push order - and 3 elements are held in total. So if a std::priority_queue program shows the title error, do not reach for the compile line - there is no mode in which <queue> 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::priority_queue the sweep in this guide finds no rescue at all among the headers probed. Each sweep program uses the priority queue 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 <vector> in that position and still no <queue>, fails with exactly the missing-include shape:
#include <vector>
int main() {
std::priority_queue<int> pq;
pq.push(3);
return pq.top() == 3 ? 0 : 1;
}
$ g++ -std=c++11 sweep_vector.cpp -o sweep_vector
sweep_vector.cpp: In function 'int main()':
sweep_vector.cpp:4:10: error: 'priority_queue' is not a member of 'std'
4 | std::priority_queue<int> pq;
| ^~~~~~~~~~~~~~
sweep_vector.cpp:2:1: note: 'std::priority_queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
1 | #include <vector>
+++ |+#include <queue>
2 |
sweep_vector.cpp:4:25: error: expected primary-expression before 'int'
4 | std::priority_queue<int> pq;
| ^~~
sweep_vector.cpp:5:5: error: 'pq' was not declared in this scope
5 | pq.push(3);
| ^~
Read what did not change. The title error is still there, word for word: the compiler still says priority_queue is not a member of std, still attaches the same header note naming <queue>, 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 <deque>, <stack>, <list>, <iostream>, <algorithm> and <functional> 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 <vector> result is the one worth pausing on. A priority queue holds its elements in a std::vector by default - the vector is its underlying container - so the two are genuinely connected, and a file that works with vectors is a plausible place to meet this error. But the container is a part the adapter uses, not the adapter: including <vector> declares the container and nothing about the adapter built on it, so the file still has no priority queue name. The <deque> result makes the same point from the other side: a deque meets the adapter's container requirements and can be named as its underlying container, yet including <deque> alone declares no adapter either. And <functional>, which declares the std::greater comparison the last section uses, does not declare the queue that comparison would order. So of the seven headers probed in place of <queue>, all seven 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 <queue> itself in every file that names std::priority_queue.
The fix: include <queue>
The header included, and the adapter is fully usable in any standard mode. This program pushes five values into a priority queue, prints the top element and the size, removes the top with pop(), and prints the new top and size:
#include <iostream>
#include <queue>
int main() {
std::priority_queue<int> pq;
pq.push(3);
pq.push(1);
pq.push(4);
pq.push(1);
pq.push(5);
std::cout << pq.top() << " size " << pq.size() << "\n";
pq.pop();
std::cout << pq.top() << " size " << pq.size() << "\n";
return 0;
}
$ g++ -std=c++11 p4_fix.cpp -o p4_fix
$ ./p4_fix
5 size 5
4 size 4
Every name that failed before now resolves. The values are pushed in the order 3, 1, 4, 1, 5, and none of that order survives in what the queue reports: top() reads the largest element, 5, while size() reports all five elements held. pop() removes that top element - it returns nothing, so the value is read with top() before the pop, as here - and the next line shows the new state: the largest of the remaining values, 4, is on top, and the size has fallen to 4. Repeating the read-and-pop pair drains the queue in descending order, which is the adapter's whole contract. Every printed value here is fully determined by the values in the program, and any other output means the program, not the machine, differs.
The ordering flipped: std::greater puts the smallest on top
The default ordering is a choice the type's third template parameter records, not a fixed property of the adapter. Naming std::greater<int> as the comparison - with the underlying container written out as std::vector<int>, since the comparison is the third parameter and the container is the second - turns the same adapter into a smallest-first queue. This program pushes the same first three values as the included-header program and prints the top:
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
int main() {
std::priority_queue<int, std::vector<int>, std::greater<int>> pq;
pq.push(3);
pq.push(1);
pq.push(4);
std::cout << pq.top() << "\n";
return 0;
}
$ g++ -std=c++11 p7_minheap.cpp -o p7_minheap
$ ./p7_minheap
1
Same pushes, opposite end on top: 3, 1 and 4 go in, and top() reads 1, the smallest, where the default queue in the earlier program read 4 from the identical pushes. Nothing else about the interface changes - push, pop, top and size are the same members with the same meanings, and reading and popping in turn now drains the queue in ascending order. Note what this program needed beyond <queue>: <functional> for std::greater and <vector> for the container named in the type - three headers, each declaring one name the program uses, and none of them standing in for another, exactly as the sweep above measured for <functional> and <vector> in place of <queue>.
Neighboring error: a priority queue has no front()
Once <queue> is included, a different error appears when the top element is read the way a plain queue or a container would read its first element. A priority queue has no front() member - its only element access is top() - and calling front() fails like this:
#include <queue>
int main() {
std::priority_queue<int> pq;
pq.push(3);
return pq.front() == 3 ? 0 : 1;
}
$ g++ -std=c++11 p5_neighbour_front.cpp -o p5_neighbour_front
p5_neighbour_front.cpp: In function 'int main()':
p5_neighbour_front.cpp:6:15: error: 'class std::priority_queue<int>' has no member named 'front'
6 | return pq.front() == 3 ? 0 : 1;
| ^~~~~
The contrast separates the two errors cleanly. This error says nothing about a missing name in std - the include is already right, the type was found and built, and the failure is a member that does not exist on it: the compiler names the class, std::priority_queue<int>, and the missing member, front. The title error names priority_queue itself as not a member of std, because the type was never there to be used. The repair here is to read the element the adapter's way: pq.top(), which returns the largest element - for the program above, the 3 it pushed. The front() habit comes from the adapter's relatives: std::queue, declared by the same <queue> header, reads its oldest element with front(), and the underlying containers read theirs the same way - but the priority queue is neither, and its top is not a front in arrival order, it is the largest element present.
Neighboring error: a priority queue has no begin()
The other neighboring fault also keeps the right include, and it comes from treating the adapter as a container that can be walked. A priority queue offers no iterators - there is no begin() member - and asking for one fails like this:
#include <queue>
int main() {
std::priority_queue<int> pq;
pq.push(3);
return *pq.begin() == 3 ? 0 : 1;
}
$ g++ -std=c++11 p6_neighbour_begin.cpp -o p6_neighbour_begin
p6_neighbour_begin.cpp: In function 'int main()':
p6_neighbour_begin.cpp:6:16: error: 'class std::priority_queue<int>' has no member named 'begin'
6 | return *pq.begin() == 3 ? 0 : 1;
| ^~~~~
Nothing in this outcome says a name is missing from std - the include is right, the queue was built, and the failure is again a member the adapter does not have. That absence is deliberate: the elements inside a priority queue are kept in heap order, not sorted order, so a walk from begin() to end() would show an arrangement that is neither the push order nor the priority order, and the adapter does not offer it. The repair is to take the elements the adapter's way: read top(), then pop(), and repeat until empty() reports the queue drained - the sequence that produces is fully sorted, descending under the default comparison, which is stronger than anything a walk could show. A program that needs to look at every element without consuming the queue copies the queue first and drains the copy, leaving the original intact.
Decision summary
- The first errors are
'priority_queue' is not a member of 'std', with a note under it saying'std::priority_queue' is defined in header '<queue>'; did you forget to '#include <queue>'?: the header is missing - add#include <queue>, exactly as the note says; every later error in the cascade traces to the absent name. - The first error is
'priority_queue' 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<queue>the same way. - The file already includes
<queue>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::priority_queuehas 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
<vector>,<deque>,<stack>,<list>,<iostream>,<algorithm>and<functional>in place of<queue>left the title error in place - among the headers probed, none declares this name by accident, and<vector>and<deque>in particular do not, even though both can hold the adapter's elements; add<queue>itself. - The error instead is
'class std::priority_queue<int>' has no member named 'front': the type was found and the member is the fault - a priority queue's only element access istop(), which returns the largest element present; read the top withtop(), and remember thatpop()removes it without returning it, so read before popping. - The error instead is
'class std::priority_queue<int>' has no member named 'begin': the type was found and the missing member is deliberate - the adapter offers no iteration, because its elements are held in heap order; drain a copy with thetop()andpop()pair to see every element in priority order.
Checklist
- The file includes
<queue>itself - not a neighboring header in its place; in the sweep above, each of the seven probed headers left the title error in place, so none of them stands in for<queue>. - No language-mode change is part of this fix:
std::priority_queuedates from C++98, and with<queue>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 read with
top()only - neverfront(),back(), or an index;top()returns the largest element under the default comparison, or the smallest when the comparison isstd::greater. - Nothing iterates over a priority queue: there are no iterators to take, and the elements are seen in priority order by reading
top()and callingpop()in turn, on a copy when the original must survive. - The fixed program compiles, runs, and prints
5 size 5and4 size 4, in order.
Related guides
- 'std::queue' Is Not a Member of 'std' Fix - the same missing-name fault on the other adapter the
<queue>header declares:std::queueis first-in, first-out and reads its oldest element withfront()- the member whose absence on a priority queue is the first neighboring error above. - 'std::stack' Is Not a Member of 'std' Fix - the same missing-name fault on the remaining container adapter:
std::stacklives in<stack>, which in place of<queue>did not rescue this name in the sweep above, and likestd::priority_queueit dates from C++98 and has no older-mode shape. - 'std::deque' Is Not a Member of 'std' Fix - the same missing-name fault on one of the two standard containers a priority queue can hold its elements in:
std::dequelives in<deque>, which in place of<queue>did not rescue this name either - naming the container never declares the adapter.
Sources
- cppreference.com, std::priority_queue — the type at the center of the error: the class template
priority_queue, defined in header<queue>, a container adapter that provides constant time lookup of the largest (by default) element at the expense of logarithmic insertion and extraction, with template parameters for the element type, the underlying container (std::vectorby default,std::dequealso satisfying the requirements) and the comparison (std::lessby default,std::greatermaking the smallest element appear as thetop()); its member list givestop,push,pop,emptyandsize, the operations the fix and repair programs use, and nofrontor iterator access. - cppreference.com, Standard library header
— what the header declares: the queueclass template, described as adapting a container to provide a first-in, first-out queue, and thepriority_queueclass template, described as adapting a container to provide a priority queue, in namespacestd, together with the comparison operators forqueueand thestd::swapoverloads for both adapters - the declarations a file gets by including<queue>itself; in the sweep above, no probed neighbor brought them in, and<vector>and<deque>did not bring the adapter name in the other direction.
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.