I usually work in C, but now I have to work with C++. I have a large file, with a lot of repetition because I can currently not traverse dir_x to dirx_z in a loop.
1. Is there a way to make the elements in this class addressable as if it was, for instance, an array? I give an example of this in the last line.
2. I currently refer to
Node * dir_x;
as being a link, but what is the real name so I can google it?
class Node {
public:
Node(int x, int y, int z){
//Will be initialized to point to the next Node (neighbor)
//So will be holding elements of this same class!
dir_x = NULL;
dir_y = NULL;
dir_z = NULL;
}
//These are "links", but does anybody know the name to google it?
Node * dir_x;
Node * dir_x;
Node * dir_x;
};
//Code snippet of a function:
//current would be the node to traverse through the collection
Node * current = someNode;
//together with next
Node * next = NULL;
//Here the next node is actually set
next = current->dir_x;
//But I would like a generic way like below
//to reduce code duplication by about a third:
next = current->dir[i];