Here is a snippet of my code:
<code>
list< MyClass * >outgoing_poo l;
MyClass* GetWaitingObjec t(string freq)
{
MyClass *temp_ptr = NULL;
list<MyClass*>: :iterator i;
for(i=outgoing_ pool.begin(); i!=outgoing_poo l.end(); i++)
{
if( (*i)->GetFrequency () == freq ) //match
{
temp_ptr = *i;
//remove item from list
outgoing_pool.e rase(i);
}
}
return temp_ptr;
}
</code
This function is supposed to iterate through the list and remove a match
(if found). However, I'm getting a segmentation fault on the
(*i)->GetFrequency () call. This only happens after an element has been
erase()'ed out of "outgoing_pool" . Does the iterator i need to be
"updated" or some such after a call to erase? I was thinking that it
was smart enough to handle this but now I'm not so sure...
I guess my question is (not totally related to the above code, but...)
what is a good way to iterate through a std::list and remove selected
elements?
Thanks,
S