In Java, I am able to define a variable of a generic class without specifying type.
class Tree<T extends Comparable<? super T>> {}
somewhere-else: Tree tree;
I can then read in some object from a file and type-cast it to the class type I desire.
tree = (Tree<String>) some object;
With boost::variant
I have begun a variant definition.
typedef boost::variant<Tree<std::string>, Tree<int>> TreeVariant; TreeVariant tree;
I know I need to specify a visitor class
but it is not clear from this example how to define it such that I am able to assign to my tree
variable either Tree<std::string>
or Tree<int>
.
I would then like to proceed from there to call member functions of Tree using the variable tree
.