Line 27. This isn't necessary. Any code that can call the Me() method on an instance can just that instance directly. Put another way, if
node->Me()
is better than
node
, then isn't
node->Me()->Me()
even better? How about
node->Me()->Me()->Me()
?
Line 29 & 35: the vector is only valid until the next call that modifies the vector of children. That might be okay, but I thought I'd point it out. You might want to store the children as a vector of pointers instead of a vector of instances.
Line 51. This is necessary because you're storing the items as a vector of instances instead of pointers. So another good reason to store a vector of pointers.
Line 56: I'd have this find the ID within the current node's descendants. If someone wants to find the node within the entire tree then let them call the function on the root node.
Line 60: Same comment as for line 56.
Line 69 & 13: Hmm. What happens when you copy a node? The copy will have the same ID as the source. Is that what you want? It's fine when copying the vector of children, but is it always the right thing? Yet another reason to store a vector of pointers to nodes.
Line 74: Why have a static method that takes a pointer to an instance? Why not just make this an ordinary method with no parameter?
Line 76: Why go to the trouble to create a vector of pointers? Why not make line 77:
for (auto &child : m_children)
and make matching changes to lines 77 & 78?
Line 84: Make this an ordinary method instead of static:
CNode<T>* RecursionIsNodeFound(int ID)
how can i copy a node? i mean the inherited data (= template parameter) each node contains ? |
If you store a vector of pointers instead of a vector of instances then you can make a copy constructor that will create a new ID instead of copying the old one.