Thread: Deleting object after list removal (C++ visual studio)

  1. #1
    Registered User
    Join Date
    Sep 2003

    Deleting object after list removal (C++ visual studio)


    so, I have a list of objects taht i made (they're calle Cgate objects)

    they're in a list. I made a routine that will search through the list and find what it wants to delete..

    so what i have so far is.. i can search through the list, and remove the object from the list..

    but i'm trying to delete the actual object..when i throw in some code to delete the object, the list search and removal code doens't work anymore.. here's the code.. what do you guys think?

    PHP Code:
    case REMOVE:

                while (
    pos != NULL)
    CGatepGate gateList.GetNext(pos);

    pGate->GateID == WhichGate)
    pGate gateList.GetPrev(pos);
    //delete pGate;
    CurrentOperation NOTHING// to get out of "delete mode"

    break; // when found and deleted stop going through list

                    else if(
    pos == gateList.GetTailPosition())
    pGate gateList.GetNext(pos);
    pGate gateList.RemoveTail();


    see where i have the // delete Cgate

    i thought i could delete the object like that, but it seems to screw my list up.

    it seems to screw with the location the object was in..

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Manassas, VA USA
    looks like you do a good job of identifying the node to be deleted.. and you can successfully delete the node.. and you can identify the previous node.. but does the previous node ever get linked to the 'next' node after a deletion is made....?
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    Sep 2003
    i read that the removeAt() function takes care of that for you..

    from what i read.. the following happens

    if you have a list

    PHP Code:

    you do removeAT(1this would make a new list with just
    it say's it takes care of it for you.. i guess it doesn't? because like i said.. as the code stands above.. it works.. but when i uncomment that delete pGate; line.. then it acts screwy

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  2. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  3. circular doubly linked list help
    By gunnerz in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 08:38 PM
  4. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  5. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM