Re: list.remove() crash.
From: James Ryan (___at__jryan@__icescape.__com)
Date: 05/14/04
- Next message: Jeff Partch: "Re: Quick Question!"
- Previous message: Jim Howard: "Windows 98 rendering problem using CDHtmlDialog"
- In reply to: Polaris: "list.remove() crash."
- Next in thread: Polaris: "Re: list.remove() crash."
- Reply: Polaris: "Re: list.remove() crash."
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 14 May 2004 12:42:27 -0400
You are iterating through the list and deleting from it at the same time. I
suspect this will cause undefined behaviour. What are you trying to do?
James
"Polaris" <etpolaris@hotmail.com> wrote in message
news:uyvnAGXOEHA.2704@TK2MSFTNGP10.phx.gbl...
> Hi:
>
> I have a short code below which polulats a list with 3 strings and then
try
> to remove them by calling list.remove(). but the program crashes at the
2nd
> run in the loop (as marked below). Could you see anything I'm doing wrong?
>
> Thanks for your input.
> Polaris
> -------------------------------------------------------------
> #include <list>
>
> typedef std::list <char*>::iterator LI;
>
> int main (int argc, char* argv[])
> {
> char* array[] =
> {
> { "Test1" },
> { "Test2" },
> { "Test3" }
> };
>
> std::list <char*> mylist;
>
> for (int i=0; i<3; i++)
> mylist.push_back (array[i]);
>
> for (LI x=mylist.begin(); x!=mylist.end(); x++)
> mylist.remove (*x); // ******* crash at 2nd rund *****.
>
> return 0;
> }
>
>
- Next message: Jeff Partch: "Re: Quick Question!"
- Previous message: Jim Howard: "Windows 98 rendering problem using CDHtmlDialog"
- In reply to: Polaris: "list.remove() crash."
- Next in thread: Polaris: "Re: list.remove() crash."
- Reply: Polaris: "Re: list.remove() crash."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|