Problem with list.

Aseem Rastogi aseem@india.tejasnetworks.com
Fri Sep 23 10:50:00 GMT 2005


Hi,

Can somebody explain the following behaviour? Even after deleting the 
member of list, I am not getting segmentation fault at last line (as 
expected). Rather foo () output is what comes out.


#include<list>

list<A*> l;

int main ()
{
    A* a = new A ();

    cout << a->foo () << endl;        // Prints 0 which is OK

    l.push_back (a);

    for (list<A*>::iterator it = l.begin (); it != l.end (); it++) {
        delete (*it);
    }

    cout << a->foo () << endl;       // Should give Segmentation Fault 
but its not !!!! Prints 0 which is not OK.
}

Regards,
Aseem.

-- 
The end is always good. If it's not good, it's not the end.




More information about the Gcc-help mailing list