list的删除remove与erase的有关问题
list的删除remove与erase的问题
DrawData Jj;
list <DrawData> ::iterator p;
for(p=TempPathDatList.begin();p!=TempPathDatList.end();p++)
{
Jj=*p;//读链表中
switch(Jj.Type)
{
case 'A ':
{
if((fabs(FrontPathPoint.Xx-Jj.Dat.ARC.x2) <=eps)&&(fabs(FrontPathPoint.Yy-Jj.Dat.ARC.y2) <=eps))
{
TempPathDatList.erase(p);//会死机
TempPathDatList.remove(Jj);//会出错
}
} break;
}
用erase会死机;
用remove会:[C++ Error] _list.h(473): E2093 'operator== ' not implemented in type 'DrawData ' for arguments of the same type
typedef struct
{
short ColorPen;//笔色
short ColorBrush;//填充刷颜色
short LineWide;//线宽度
short LineType;//线型
short Layer;//所处层
//bool Delete;//是否处于删除状态
char Type;//类型标志:元素名称
int id_only;//图形元素唯一的识别号
union
{
struct
{
float x0,y0,x1,y1,x2,y2,r,length,angle_s,angle_e;//圆心,起点,终点
char NS;//逆顺标志
}ARC;//圆弧
}Dat;
}DrawData;
如何现实正确的删除
------解决方案--------------------
注意,list的remove即是erase,所以remove后不需要另行erase了。
DrawData Jj;
list <DrawData> ::iterator p;
for(p=TempPathDatList.begin();p!=TempPathDatList.end();p++)
{
Jj=*p;//读链表中
switch(Jj.Type)
{
case 'A ':
{
if((fabs(FrontPathPoint.Xx-Jj.Dat.ARC.x2) <=eps)&&(fabs(FrontPathPoint.Yy-Jj.Dat.ARC.y2) <=eps))
{
TempPathDatList.erase(p);//会死机
TempPathDatList.remove(Jj);//会出错
}
} break;
}
用erase会死机;
用remove会:[C++ Error] _list.h(473): E2093 'operator== ' not implemented in type 'DrawData ' for arguments of the same type
typedef struct
{
short ColorPen;//笔色
short ColorBrush;//填充刷颜色
short LineWide;//线宽度
short LineType;//线型
short Layer;//所处层
//bool Delete;//是否处于删除状态
char Type;//类型标志:元素名称
int id_only;//图形元素唯一的识别号
union
{
struct
{
float x0,y0,x1,y1,x2,y2,r,length,angle_s,angle_e;//圆心,起点,终点
char NS;//逆顺标志
}ARC;//圆弧
}Dat;
}DrawData;
如何现实正确的删除
------解决方案--------------------
注意,list的remove即是erase,所以remove后不需要另行erase了。