Dijkstra 알고리즘을 구현하려고합니다. 나는이 priority_queueDijkstras algorithm with 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 에는 기본 생성자이없고 은을 만들 수 없습니다. 내 코드를 컴파일하려면 어떻게해야합니까? BTW이이이이이 pathcomppl.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;
}
에게 있습니다
#include "pathcomp.h"
class PathCompPL:public PathComp{
public:
virtual bool betterThan(const PathInfo& path1,const PathInfo& path2);
};
pathcomppl.h에게 있습니다
class PathComp{
public:
virtual bool betterThan(const PathInfo& path1,const PathInfo& path2)=0;
};
pathcomp.h에게 있습니다
error: no matching function for call to 'QueueComp::QueueComp()'
오류입니다
확장 된 오류 메시지
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
QueueComp 유형에 기본 생성자가 필요하다고 생각합니다. – Borgleader
그것은 그렇게 보인다. 그러나 나는 하나를 사용할 것을 권한다. – Slazer
우선 순위 큐에 에지 가중치를 저장하여 항상 가장 짧은 에지를 선택할 수 있습니다. – vik