简体   繁体   中英

Priority Queue Declaration C++

I have been rather frustrated at this for awhile and i just can't seem to find where error is (note my compiler does not support c++11)

basically i am trying to construct a priority Queue where each element contains two further elements. The first element being a queue of char vectors and the second being a heuristic to evaluate this queue.

The contents of the queue of char vectors are not important just the evaluation of the heuristic (greater) as follows

struct pathP
{
public:
    queue<vector<char>> que;
    int hue;
};

struct pathComp
{
    bool comp(const pathP &s1, const pathP &s2) const
    {
        return s1.hue < s2.hue;
    }
};

----------------------- (in a function elsewhere in my code)

priority_queue<pathP, vector<pathP>, pathComp> endV;
queue<vector<char>> saveQ;
pathP pathStore;
int h1, heur;

----------------------- (further down the function)

pathStore.que = saveQ;
heur = h1;
pathStore.hue = heur;
endV.push(pathStore); //error C2064

error c2064 reads "term does not evaluate to a function taking 2 arguments" and i am not sure how to fix it

struct pathComp
{
    bool operator()(const pathP &s1, const pathP &s2) const
    {
        return s1.hue < s2.hue;
    }
};

priority_queue doesn't use a method called comp . Instead you should define a functor which is a class which overrides operator() as above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM