[prog] C++ - linked list and segmentation fault

Kathryn Hogg kjh at flyballdogs.com
Tue Apr 8 19:15:58 EST 2003


Jennifer Davis said:
> I am still having some difficulty with the
> deAlllocation function ...


> void deAllocate(INVENTORY_NODE *pStart){
>     INVENTORY_NODE* current;
>     INVENTORY_NODE* temp;
>     current=pStart;
>     while (current !=NULL){
>         temp->nextItem=current;
>         delete current;
>         current=temp;
>         } // end while
>     } // end deAllocate


You're making a similar mistake here because temp hasn't been assigned
anything when you have assigned to temp->nextItem.  You have the right
idea but just got something a little backwards.  What you what to do is
assign temp to the next item after current.

-- 
Kathryn


More information about the Programming mailing list