簡體   English   中英

優先隊列聲明C ++

[英]Priority Queue Declaration C++

我已經對此感到沮喪了一段時間,我似乎找不到錯誤在哪里(注意我的編譯器不支持c ++ 11)。

基本上,我試圖構造一個優先級隊列,其中每個元素都包含另外兩個元素。 第一個元素是char向量的隊列,第二個元素是評估此隊列的啟發式方法。

char向量隊列的內容並不重要,只是對啟發式(更大)的評估如下

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;
    }
};

-----------------------(在我代碼其他地方的函數中)

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

-----------------------(進一步下移功能)

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

錯誤c2064讀取“項不求值為帶有2個參數的函數”,但我不確定如何解決它

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

priority_queue不使用稱為comp的方法。 相反,您應該定義一個仿函數 ,該仿函數是一個類,該類重寫上面的operator()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM