C++中priority_queue的比较函数重载的两种方式

时间:2014-10-03 16:40:34   收藏:0   阅读:292

1.定义比较函数,以函数对象形式

    这种方式使用时,需要把函数加入priority_queue的声明中去

 struct com{

  bool operator()( T &t1, T &t2)

    {

 

 }

};

priority_queue<T, vector<T>, com>  que;

2.在结构体中重载<操作符(重载为友元函数)

class T{


public:

friend bool operator<(const T &t);

};

priority<T, vector<T> ...

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!