2010-12-15 120 views
0

这已经让我坚持了3个小时。有人看到这个不起作用的原因吗?stl的自定义比较器

struct sortByPropRev 
{ 
    bool operator()(const cust_type &a, const cust_type &b) const 
    { 
     return a.prop > b.prop; 
    } 
}; 
... 
priority_queue<cust_type, vector<cust_type>, sortByPropRev> x; 

我得到的编译错误:
Error C2664: 'bool (cust_type &,cust_type &)' : cannot convert parameter 1 from 'const cust_type' to 'cust_type &'

和2更多的只是喜欢它,但在不同线路上的algorithm.h

+0

cust_type是如何定义的? – 2010-12-15 14:58:18

+0

'struct cust_type {int a,int b,...; cust_type(int a,int b,...):a(a),b(b){}}' – baruch 2010-12-15 15:01:58

回答

0

没关系。我发现了这个问题。我是在调用相同算法函数的代码的不同部分。抱歉打扰大家,并感谢您尝试提供帮助。

0

你给它b.pprop,VS a.prop。我想给出编译器无法正确解析结构定义的错误 - 检查刚才在其上的代码中的语法错误。

+0

这是这里的拼写错误,而不是原始代码 – baruch 2010-12-15 15:00:11