【发布时间】:2013-03-10 18:11:18
【问题描述】:
我想在 C++ 中创建 Edge 类的 priority_queue。
为此,我创建了edgeCompare 比较器类,如下所示:
class edgeCompare{
public:
map<int, glm::mat4x4> * Qmap;
edgeCompare(const map<int, glm::mat4x4> & Qm){
* Qmap = Qm;
}
bool operator() (const Edge & e1, const Edge & e2) const{
// code that compares and returns corresponding bool
// OBS: in this function I use *Qmap
}
}
如您所见,我需要一个外部变量来进行比较。
priority_queue 通常声明为:
priority_queue<Edge, vector<Edge>, edgeCompare> pq;
但就我而言,我需要使用我的变量 Qmap 构造 edgeComparator。
我应该如何进行?
非常感谢!
【问题讨论】:
-
你是怎么解决这个问题的?我想做类似的事情。
标签: c++ priority-queue comparator