C++11 C++如何在类中的优先级队列中使用比较器

C++11 C++如何在类中的优先级队列中使用比较器,c++11,priority-queue,C++11,Priority Queue,我正在按照科尔曼的书写一个Dijsktra程序。这里,我有一个类图,它有一个dijsktra方法。我需要在这个方法中使用优先级队列Q。有两个数组最短[]和pred[]。此Q应根据最短[]值对顶点进行排序。 每个节点都表示为int 使用比较器声明优先级队列时出错。 非常感谢您的帮助 class Graph { private: vector<int> vertex; map<int, vector<int> > adjlist; int

我正在按照科尔曼的书写一个Dijsktra程序。这里,我有一个类图,它有一个dijsktra方法。我需要在这个方法中使用优先级队列Q。有两个数组最短[]和pred[]。此Q应根据最短[]值对顶点进行排序。 每个节点都表示为int

使用比较器声明优先级队列时出错。 非常感谢您的帮助

class Graph {
private:
    vector<int> vertex;
    map<int, vector<int> > adjlist;
    int *shortest,*pred;
public:
    Graph(int V){
        fore(i,V) { vertex.pb(i); }
        shortest = new int[V];
        pred = new int[V];
    }
    struct Comp {                     // Error!
        Comp(Graph& g): graph(g){     // Error!
        }
        Graph& graph;
        bool operator()(int i1, int i2) {
            return graph->shortest[i1] > graph->shortest[i2];
        }
    };
    Comp comp;
    void dijsktra(int s);
 };
    void Graph::dijsktra(int s) {
        int n = vertex.size();
        fore(i,n) {
            shortest[i] = 99;
            pred[i] = 0;
        }
        shortest[s] = 0;

        priority_queue<int,vector<int>, Comp> Q(comp); // Error!

    }

提供错误消息write,使用multi_映射作为要启动的优先级队列。让它工作起来,然后担心优化。修复这个:Comp-Comp;如果可以,下次用clang++编译。错误消息比gccGraphint V:comp*this{@IgorTandetnik:Changing constructor to Graphint V:comp*提供的消息更有用。这将成功编译。谢谢。
dag.cpp: In constructor ‘Graph::Graph(int)’:
dag.cpp:15:14: error: no matching function for call to ‘Graph::Comp::Comp()’
  Graph(int V){
              ^
dag.cpp:15:14: note: candidates are:
dag.cpp:21:3: note: Graph::Comp::Comp(Graph&)
   Comp(Graph& g): graph(g){
   ^
dag.cpp:21:3: note:   candidate expects 1 argument, 0 provided
dag.cpp:20:9: note: constexpr Graph::Comp::Comp(const Graph::Comp&)
  struct Comp {
         ^
dag.cpp:20:9: note:   candidate expects 1 argument, 0 provided
dag.cpp:20:9: note: constexpr Graph::Comp::Comp(Graph::Comp&&)
dag.cpp:20:9: note:   candidate expects 1 argument, 0 provided
Compilation failed.