T
Timothy Madden
Hello
I have a linked list of object of a class. I thought it would be nice to
have the destructor delete the whole list when I delete just the first
element. I don't want to recursivly destroy the list elements; the list is
arbitrary long. Something like this:
class ListElem
{
char Datum[1000];
class ListElem *Next;
ListElem()
{ Next = NULL; }
~ListElem()
{
class ListElem *el;
while (Next)
{
el = Next;
Next = Next->Next;
delete el;
}
}
}
but the last instruction delete el; will make a recursive call to the
destructor and it's all going down.
How can I delete an element, from the destructor, without calling the
destructor again ?
Thank you
Timothy Madden
Romania
I have a linked list of object of a class. I thought it would be nice to
have the destructor delete the whole list when I delete just the first
element. I don't want to recursivly destroy the list elements; the list is
arbitrary long. Something like this:
class ListElem
{
char Datum[1000];
class ListElem *Next;
ListElem()
{ Next = NULL; }
~ListElem()
{
class ListElem *el;
while (Next)
{
el = Next;
Next = Next->Next;
delete el;
}
}
}
but the last instruction delete el; will make a recursive call to the
destructor and it's all going down.
How can I delete an element, from the destructor, without calling the
destructor again ?
Thank you
Timothy Madden
Romania