0

it is within my intention to write a Binary Search Tree in C++ that is going to made us of by some concurrent processes. As I am taking a stream of different types of objects (UserNode, etc) I am trying to write it such that these different node types inherit from the basic node type. Insertion works with this setup.

As the concurrent processes iterate the tree and are supposed to do different things depending on what type the node is i am trying to make use of typeid().name(). Though after insertion into the tree all nodes are automatically cast to the basic node type and the original typename is lost. it was my goal to use the typename as sort of a way to prevent having to use another variable in each node for node type classification in the concurrent processes.

Any ideas my bros? (templates are out of the question as they still cause the node type to be consistent in each individual tree)

  • Have a look here: http://www.cplusplus.com/reference/type_traits/ – Tanuki Aug 14 '14 at 12:44
  • What about using polymorphism and having the concurrent process tell each node to go do something? Then depending on the actual type of the Node, the action specific to that Node type will occur. – jtomschroeder Aug 14 '14 at 13:59
  • Make a tree of `std::unique_ptr`s to nodes to avoid [slicing](http://stackoverflow.com/q/274626/1639256) and evaluate [`std::type_index`](http://en.cppreference.com/w/cpp/types/type_index) for comparing derived types of nodes. – Oktalist Aug 14 '14 at 13:59

0 Answers0