Nodes

Pressure

Newbie
Joined
Jul 3, 2003
Messages
5,065
Reaction score
0
I've been programming in C++ for a while now and I haven't really found a good site that explains what a node is and what it does. I know its the '->' thing in the code. I searched through the HL SDK .cpp files and right now the nodes are the only thing I don't understand. If someone could explain them to me I would be grateful.
 
The only thing I know about nodes is in Hammer :/, you place "info_nodes" everywhere, and monsters can follow them
 
oh wow thanks i was about to ask the same question myself
 
hmm wow, this is such a basic thing, I mean I guess you never really use it unless you hit a data structures class, basically a node usually refers to a data structure or object that points to another object of the same or similar type, that is to say the structure/object/class contains a pointer type of it's own class or a superclass.

ex:

class node
{
node* next;
};

now next can point to any node or any class derived from node, now a bit more of an example:

void foo ()
{
node bar1;
node bar2;
bar1.next = bar2;
//now we can access bar2 in two ways
//the first is with the . operator
(*(bar1.next)).next = void;
//and the second is with the -> operator
bar1.next->next = void;
//in C++ this is generally not used because you would design
//a method to be used to directly access the next node.
//but within methods you may use something along these lines.
};

edit:(gah so simple and I still screw up)
 
yes, to elaborate on that a node is basically a single part of a link list, or a set of data. It contains a pointer that will eventually point to the next node (could be created as a class, or a struct).
 
I didn't want to use linked lists in this case because you may be using trees of various types as well, though strictly speaking it is refferred to as a leaf, node is also a way of refferring to the objects used in trees, especially if they are bound in a list as well as a tree.
 
Back
Top