我正在尝试初始化priority_queue,这是代码
class stdnt{
public:
int indx;
int c;
int lvl;
bool operator<(const stdnt &x)
{
return this->c > x.c;
}
};
priority_queue<stdnt> pq;
但是它给了我错误传递const&amp;丢弃限定符。我该怎么办呢?
答案 0 :(得分:6)
您需要设置运算符const
,以便可以在const
个实例上或通过const
引用或指向const
的指针调用它:
bool operator<(const stdnt &x) const
^^^^^
或者,将其设为非会员:
bool operator<(const stdnt &lhs, const stdnt& rhs)
{
return lhs.c > rhs.c;
}