-
Priority Queue :: C++
Hi.
Visual C++ .NET outputs this error when I try to declare a priority queue with reverse sorting.
-----
// Assuming program runs and before I added the following.
#include <queue>
#include <functional>
std::priority_queue<int, std::greater<int>> m_nQueueList;
// I try this declaration, but receive the exact same
// error everytime.
std::priority_queue<int, std::vector<int>, std::greater<int>> m_nQueueList;
-----
Here is the error from Visual C++ .NET
-----
C2065: 'm_nQueueList' : undeclared identifier
error C2143: syntax error : missing '>' before ';'
error C2146: syntax error : missing ',' before identifier 'm_nQueueList'
error C2208: '<Unknown>' : no members defined using this type
error C2947: expecting '>' to terminate template-argument-list, found '>>'
error C2976: 'std::priority_queue' : too few template arguments
-----
Does anyone know what the problem is?
Thanks,
Kuphryn
-
Code:
std::priority_queue<int, std::vector<int>, std::greater<int>> m_nQueueList;
does this '>>' look familair? It is being parsed as the left shift operator. You need a space between the two brackets.
Code:
std::priority_queue<int, std::vector<int>, std::greater<int> > m_nQueueList;
-
when u post code use the code tags like
(code)
your code here
(/code)
but instead of ( and ) put [ and ]
-
Okay. Thanks.
Added a space in between ">>" fixed it.
Here is the working solution.
Code:
std:riority_queue<int, std::vector<int>, std::greater<int> > m_nQueueList;
I would have never guessed the problem had to do with a missing space. That space operator is tricky.
Kuphryn