码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-10-03 16:40:34      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:io   使用   sp   c   on   amp   r   c++   bs   

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> ...

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

标签:io   使用   sp   c   on   amp   r   c++   bs   

原文地址:http://blog.csdn.net/aa838260772/article/details/39755531

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!