-
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?
-
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 ?
-
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.
-
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?