0
은 다음과 같다 :priority_queue 상수 식 코드에서
을 비교 한 알고리즘
class PathComp{
public:
virtual bool betterThan(const PathInfo& path1, const PathInfo& path2) const{
//returns true if path1 is shorther than path2
{
};
재정의 연산자()
class QueueComp{
private:
PathComp* comp;
public:
QueueComp(PathComp* pc);
bool operator() (const pair<PathInfo, string>& item1, const pair<PathInfo, string> item2);
};
QueueComp::QueueComp(PathComp* pc):comp(pc){}
bool QueueComp::operator() (const pair<PathInfo, string>& item1, const pair<PathInfo, string>& item2){
return comp->betterThan(item1.first, item2.first);
}
기능 사용 우선 순위 큐
list<string> Graph::shortestPath(const string& from, const string& to, PathComp* pc) const{
const QueueComp comp(pc);
std::priority_queue<pair<PathInfo, string>, set<pair<PathInfo, string> >, comp> q;
}
를 가진 클래스 컴파일러 토르가 오류 메시지를 표시합니다. 'comp'가 상수 표현식에 나타날 수 없습니다. 템플릿 인수 3이 유효하지 않습니다. 이전에 선언에 잘못된 유형이 있습니다. 토큰
누구에게 문제가 있는지 알고 있습니까? 모든 도움에 감사드립니다.
덕분에 내가 필요한 모든 것이 었습니다. 당신은 저를 많이 도와주었습니다. – franz9