-
Remove和erase都可以进行数据的移除,区别在于Remove移除的是List中所有与待移除项相等的数据,而erase移除的是迭代器所指的内容。 Remove有一个是否相等的比较,因此我们在Remove自定义的数据时,要添加“==”运算符的重载实现。
-
下面给出一个简单的演示例子:
#include<iostream>
#include<iterator>
#include <list>
using namespace std;
#define RECT_NUM 20
typedef class Rect{
public:
int left;
int right;
int up;
int down;
Rect()
{
this->left=0;
this->right=0;
this->up=0;
this->down=0;
}
bool operator ==(const Rect &other)
{
return (left==other.left)&&(right==other.right)&&(up==other.up)&&(down==other.down);
}
}Rect;
list<Rect>test_rect(RECT_NUM);
void Init()
{
list<Rect>::iterator i;
int index;
for( i=test_rect.begin(),index=0;i!=test_rect.end();i++,index++)
{
(*i).left=index;
(*i).up=