Problem with recursion

Started by
2 comments, last by Zahlman 16 years, 9 months ago
I have a bit of a problem with my code.. I've defined a bunch of classes to read skeleton information from a text file..:- Skeleton - defines the class to store the skeleton information and a pointer to the root bone of the skeleton Joint - defines a joint of the skeleton which contains various bits of joint information to be read in from the file as well as a linked list of children (of the same type) Tokenizer - defines the class used to read the token data from the text file to fill in the data for every "Joint" in the skeleton hierarchy - When my application calls Skeleton::Load() it opens the text file to be read and calls Joint::Load() on the root Joint member (passing the tokenizer as a parameter).. - Joint::Load() reads the base set of joint information (using the tokenizer) for the current joint and then checks in the text file for a child joint.. If one is found it creates a new Joint object and adds it to the children linked list of the current joint before calling Joint::Load() on the child joint (passing the tokenizer as a parameter).. - After reading the information for the child (using the tokenizer) a check for a child of the current joint is made.. When no child is found the Joint::Load() function returns which does something strange.. Before returning to the previous function in the call stack for some reason the tokenizer's destructor is called which destroys it so that when we return to check for the next token the application crashes.. Is there any specific reason this is happening (especially since the tokenizer is a child of Skeleton class and only a reference is beng passed along to each call to Load() )...? Is there anyway I can get around this? (otherwise it does kind of defeat the purpose of the recursivity) Sorry my explaination wasn't great, Hope you can help.. Archangelmorph
Advertisement
Any chance you're passing the tokenizer by value (and not by reference or via a pointer) to Joint::Load()? EDIT: Just noticed that you say it is being passed by reference but maybe double-check this because it sounds like this is the problem.

Also, if you post the code to Joint::Load() it might give us more information about your problem.
Thanks thats what it was.. (silly me.. :P )
Let's see the code anyway, please. (My spider sense is tingling...)

This topic is closed to new replies.

Advertisement