Chinaunix首页 | 论坛 | 博客
  • 博客访问: 13080
  • 博文数量: 6
  • 博客积分: 215
  • 博客等级: 入伍新兵
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-01 21:12
文章分类
文章存档

2012年(1)

2011年(5)

我的朋友

发布时间:2012-03-13 10:13:39

......【阅读全文】

阅读(633) | 评论(0) | 转发(0)

发布时间:2011-11-04 18:15:52

virtual 和非virtual的析构函数的区别......【阅读全文】

阅读(467) | 评论(0) | 转发(0)

发布时间:2011-11-04 18:02:28

C++ public protected and private 区别......【阅读全文】

阅读(3481) | 评论(0) | 转发(0)

发布时间:2011-09-01 21:47:45

......【阅读全文】

阅读(1148) | 评论(0) | 转发(0)

发布时间:2011-05-24 18:39:23

linux下awk的用法......【阅读全文】

阅读(416) | 评论(0) | 转发(0)
给主人留下些什么吧!~~

baixs19872012-03-09 13:38

dashudinglv: 我觉得你写的程序不是我想要的,我的问题还是不能解决。.....
bool operator () (T Value)
{
return Value == m_tValue;
}
这句话是主要的,如果大于你就写成
bool operator () (T Value)
{
return Value > m_tValue;
}
不就行了?他的less也是这么做的,当然operator> 是要重载的

回复  |  举报

baixs19872012-03-09 13:20

#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;

class CT
{
public:
CT(int x):m(x), n(x+1){}
void Fun(void)
{
cout << "Fun::Fun()" << endl;
};

bool operator== (const CT& c)
{
return this->m == c.m;
}
bool operator> (const CT& c)
{
return this->m > c.m;
}
bool operator>= (const CT& c)
{
return this->m >= c.m;
}
int m;
int n;
};

template <typename T>
class RemoveItem
{
private:
T m_tValue;

public:
RemoveItem(T pValue) : m_tValue(pValue){ }
bool operator () (T Value)
{
//return Value == m_tValue;
//return Value >= m_tValue;
return Value > m_tValue;

}
};

int main()
{
deque<CT> que;
CT a1(1);
que.push_back(a1);
CT a2(2);
que.push_back(a2);
CT a3(3);
que.push_back(a3);
CT a4(4);
que.push_back(a4);
CT a5(5);
que.push_back(a5);
que.push_back(a5);
que.push_back(a5);
CT a6(6);
que.push_back(a6);
CT a7(7);
que.push_back(a7);

a5.n--;

deque<CT>::iterator it = remove_if(que.begin(), que.end(), RemoveItem<CT>(a5));
que.erase(it, que.end());

return 0;
}

回复  |  举报
留言热议
请登录后留言。

登录 注册