2014-11-01 62 views
0

我正在嘗試使用C++中的STL創建類型爲Job的最小優先級隊列。我有以下代碼:帶對象的最小優先級隊列

class Job 
{ 
public: 
    int IOtime; 
}; 

struct grThan 
{ 
    bool operator()(const Job& l, const Job& r) const 
    { 
     return l.IOtime > r.IOtime; 
    } 
}; 

我聲明隊列std::priority_queue<Job, vector<Job>, grThan> IO;

我得到以下錯誤:

bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const Job'

+1

與MSVC2013編譯好。你用gcc編譯過嗎?用C++ 11選項? – Christophe 2014-11-01 19:18:30

+2

'std :: string'在哪裏以及如何進入圖片?它沒有出現在你顯示的代碼中,但錯誤消息指向它。我建議你發佈一個複製問題的小例子。 – 2014-11-01 21:24:39

回答

0
// stackoverflow_26691997.cpp (cX) 2015 [email protected] 
// http://stackoverflow.com/questions/26691997/ 

#include <queue> 
#include <vector> 

class Job { 
public: 
    int IOtime; 
}; 

struct grThan { 
    bool operator()(const Job& l, const Job& r) const { 
     return l.IOtime > r.IOtime; 
    } 
}; 

int main() { 
    std::priority_queue<Job, std::vector<Job>, grThan> IO; 
}