I thought I had this figured out, but I guess I was wrong. I was under the impression that the first element in ‘<…>’ is the type that is to be stored in the queue, the second is the container type (the choices being ‘vector’ or ‘dequeue’) and the third is the class that overloads the ‘()’ operator for comparison. Based on this, I think the following code should compile, but it does not 🙁
std::priority_queue<uint32_t*, std::vector<uint32_t*>, edgeComparator> q();
uint32_t* nodeEdge = new uint32_t[2];
nodeEdge[0] = startN;
nodeEdge[1] = 0;
q.push(nodeEdge);
‘edgeComparator’ is defined as follows:
class edgeComparator
{
public:
bool operator() (const uint32_t*& lhs, const uint32_t*& rhs) const
{
return (lhs[1]>rhs[1]);
}
};
Here is the error I’m getting:
./Graph.cpp: In member function `void Graph::findShortestPath()':
./Graph.cpp:148: error: request for member `push' in `q', which is of non-class type `std::priority_queue<uint32_t*, std::vector<uint32_t*, std::allocator<uint32_t*> >, edgeComparator> ()()'
Worse yet, I also get this error when trying ‘q.empty()’
./Graph.cpp:150: error: request for member `empty' in `q', which is of non-class type `std::priority_queue<uint32_t*, std::vector<uint32_t*, std::allocator<uint32_t*> >, edgeComparator> ()()'
You had:
But instead, you should use:
The first version declares a function named
q, that takes no arguments, and returns a value of typestd::priority_queue<...>.The second version declares a variable named
q, of typestd::priority_queue<...>, which is default-initialised.