Archived

This topic is now archived and is closed to further replies.

Solstice

Tree deallocation

Recommended Posts

For my project I wrote an STL like tree class. The class is a template that manages a tree of node classes that contain template type T. This tree class also, does not have an allocator field in it''s template params. Here''s my problem. My class T is a base class for several different subclasses. The tree only takes instances as opposed to pointers of type T. Now -- if my thinking is right -- when I insert a new instance into the tree, it''s busted down to the base class T via the copy operator. The only solution I find is to make the tree use pointers of T instead of instances. Then there''s another problem. Deallocation. Although all the node classes go through a recusive delete to delete themselves, their contained T relies on being deleted along with the class on the stack. So to pass a pointer as a template param to the tree would result in a memory leak... In my project I have since subclassed the tree template passing T as a class called Entity. I really did this just so the doxygen docs would look cleaner, but I may be able to solve all of this mess. If I make this tree subclass init with T = Entity*, I could use it''s descructor to deallocate the Entities. But how did I write such an algorithm without using the same recusive node delete I''ve used before? Here''s the tree code: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/chroma/chroma/XML/tree.h?rev=1.1 -Solstice deninet.com aeris.deninet.com "...I was given three choices, the earth, the stars, or..."

Share this post


Link to post
Share on other sites