我正在尝试实现 Dijkstra 的算法。我正在使用这个priority_queue
priority_queue<pair<PathInfo,string>,vector<pair<PathInfo,string> >,QueueComp> p;
在哪里
class QueueComp{
PathComp* pc;
public:
QueueComp(PathComp*);
bool operator ()(const pair<PathInfo,string>&,const pair<PathInfo,string>& );
};
是我的“比较”功能。错误是 QueueComp没有默认构造函数,我不允许创建一个。我该怎么做才能使我的代码编译?顺便说一句,这是错误
error: no matching function for call to 'QueueComp::QueueComp()'
这是路径comp.h
class PathComp{
public:
virtual bool betterThan(const PathInfo& path1,const PathInfo& path2)=0;
};
这是路径comppl.h
#include "pathcomp.h"
class PathCompPL:public PathComp{
public:
virtual bool betterThan(const PathInfo& path1,const PathInfo& path2);
};
这是路径comppl.cpp
#include "pathcomppl.h"
bool PathCompPL::betterThan(const PathInfo& path1,const PathInfo& path2){
if (path1.getTotalPrice()>path2.getTotalPrice())
return true;
if (path1.getTotalPrice()==path2.getTotalPrice() && path1.getTotalLength()>path2.getTotalLength())
return true;
return false;
}
扩展的错误消息
main.cpp: In constructor ‘std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Sequence&) [with _Tp = std::pair<PathInfo, std::basic_string<char> >; _Sequence = std::vector<std::pair<PathInfo, std::basic_string<char> > >; _Compare = QueueComp]’:
main.cpp:11:87: error: no matching function for call to ‘QueueComp::QueueComp()’
main.cpp:11:87: note: candidates are:
In file included from main.cpp:5:0:
queuecomp.h:14:5: note: QueueComp::QueueComp(PathComp*)
queuecomp.h:14:5: note: candidate expects 1 argument, 0 provided
queuecomp.h:10:7: note: QueueComp::QueueComp(const QueueComp&)
queuecomp.h:10:7: note: candidate expects 1 argument, 0 provided