Home
This Site
About Me
Old News

Projects
Robot Race
MMORPG
Chatter
Role Playing Game
Solar System
C++ 3D Game Engine
DreamScape
3D Demo Engine
Vapor Trail

Tutorials
Physics - Gravity
Plane Collision
Backface Culling

C++ Classes
CObject
CNode
CTexture
CPlane
CMatrix
CVector

Links
Personal
Sites
Tutorials


Hosted by
 

Node Class


Down to Business

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)






Copyright © 2000 Bas Kuenen. All rights reserved.
This site is optimised for 1024x768+ resolution (hi-color) with MS Internet Explorer.