#include#include #include using namespace std;class Timer;typedef Timer* RTimer;class Timer{public: Timer():_interval(0),_expires_time(0){} virtual ~Timer(){} virtual void schedule_timer(int sec,int usec = 0) { } virtual long expires_time() { return this->_expires_time; } virtual long interval_time() { return this->_interval; }public: long _interval; long _expires_time;};struct RTimerCmp{ bool operator()(RTimer left,RTimer right) { if(left->_expires_time == right->_expires_time) { return right->_expires_time > left->_expires_time; } else { return left->_expires_time > right->_expires_time; } }};std::priority_queue ,RTimerCmp > _rtime_queue;int main(){ Timer timer1; timer1._expires_time = 1; Timer timer2; timer2._expires_time = 2; Timer timer3; timer3._expires_time = 3; _rtime_queue.push(&timer1); _rtime_queue.push(&timer3); _rtime_queue.push(&timer2); while(true) { if(_rtime_queue.size() <= 0) { break; } RTimer r = _rtime_queue.top(); cout << "expire " << r->_expires_time << endl; _rtime_queue.pop(); } return 0;}
:-),记录一下!
stl 容器 优先级队列 指针