Getting tired of copy-pasting from your old code, and spending hours coding the same things?
Here's another class to make your life easier. (or harder, if you think the right name should be C--)
This class is a cyclic linked list AND a tree, all in one.
You probably have seen this stuff before, so what's so good about this one, you ask?
Well - the code is small, easy to understand, easy to use and clean.
Not perfect yet - but I'll leave that up to you...
How do I use it?
Attach and detach. These children are all attached to it's parent:
CNode Parent;
CNode ChildA(&Parent);
CNode ChildB;
Parent.Attach(&ChildB);
CNode ChildC;
ChildC.AttachTo(&Parent);
Children are deleted automaticly, when a parent dies.
The destructor is virtual, so the destructors of derived classes are also called, when deleted automaticly.
CNode *pParent = new CNode;
pParent->Attach(new CNode);
delete pParent;
Advanced example using a constructor: (CKnight & CSword derived from CNode)
CKnight::CKnight()
{
Attach(new CSword);
}
Give me the Source
As always, code can be improved.
But I'm already using this stuff for months and I'm still happy with it.
Anyway - here it is: (just click for direct look at the source)