我以为我已经弄清楚了,但我想我错了。我的印象是“<...>”中的第一个元素是要存储在队列中的类型,第二个是容器类型(选择是“向量”或“出队”),第三个是是重载 '()' 运算符以进行比较的类。基于此,我认为以下代码应该编译,但它没有:(
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' 定义如下:
class edgeComparator
{
public:
bool operator() (const uint32_t*& lhs, const uint32_t*& rhs) const
{
return (lhs[1]>rhs[1]);
}
};
这是我得到的错误:
./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> ()()'
更糟糕的是,我在尝试 '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> ()()'