Thread: Linked list problem

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    411

    Linked list problem

    my program keeps charshing before it dose anything, ive narrowed the problem down to this section of code.

    if(next!=TPartTail) next->Draw();

    It should call the Draw function of the object pointed to by next if its not TPartTail, when the program start next gets initilized to TPartTail. I dont understand what could possable be wrong, but if I remove the logical checks for TPartTail then the program runs.

    TPartTail is a global variable that only appears in one source file.

    its declared as

    TPartNode* TPartTail = new TPartNode;

    And the default constructor for TPartNode is

    TPartNode::TPartNode() {
    next = TPartTail;
    prev = TPartHead;
    }

    any thoughts? Need more code/explanation?

  2. #2
    Unregistered
    Guest
    I've had something exactly like this,
    but couldn't figure out the problem.

    Why would the if statement cause an error?

    are those two values of the same type ?

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    next and TPartTail are the same type, and the only way I can get my code to run is if I remove the logical check.


    I figured it out now, the order things were being done was the problem. I put in an init function instead of useing a constructor (not all the variables that were being used were defined yet) and it works fine.
    Last edited by Eber Kain; 04-18-2002 at 12:13 PM.

  4. #4
    Unregistered
    Guest
    do you initialize both TPartTail and next to a value before you try to equate them? Are you trying to equate the address of the item you are pointing too or the value in the item you are pointing to?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 06:16 PM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  3. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM