sun307
asked on
removing a node from C++ list
Hi !
following is some code. the problem is with the remove() function coded below.
i want to remove the nodes found in the list which is pretty clear from the remove function, but removal is not working....
kindly help...
struct WinTable {
int id;
HWND hNWnd;
};
typedef list<WinTable> LT;
typedef list<WinTable>::iterator WI;
LT table;
//////////////////////////
void remove(int logicalID)
{
for(WI i=table.begin(); i!=table.end(); ++i)
{
if(i->id==logicalID)
table.remove(i); //erroneous code
}
}
-Best regards
Sun307
following is some code. the problem is with the remove() function coded below.
i want to remove the nodes found in the list which is pretty clear from the remove function, but removal is not working....
kindly help...
struct WinTable {
int id;
HWND hNWnd;
};
typedef list<WinTable> LT;
typedef list<WinTable>::iterator WI;
LT table;
//////////////////////////
void remove(int logicalID)
{
for(WI i=table.begin(); i!=table.end(); ++i)
{
if(i->id==logicalID)
table.remove(i); //erroneous code
}
}
-Best regards
Sun307
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx Nietod !!
===============
===============
list::erase() erases an element specified by an iterator, so this is the type of erasure/removal you are trying to do.
void remove(int logicalID)
{
for(WI i=table.begin(); i!=table.end(); ++i)
{
if (i->id==logicalID)
table.erase(i); //erroneous code
}
}