title: Boost::Variant; Defining Visitor Class
body: <p>In Java, I am able to define a variable of a generic class without specifying type.</p>
  
  <pre><code>class Tree&lt;T extends Comparable&lt;? super T&gt;&gt; {}
  somewhere-else: Tree tree;
  </code></pre>
  
  <p>I can then read in some object from a file and type-cast it to the class type I desire.</p>
  
  <pre><code>tree = (Tree&lt;String&gt;) some object;
  </code></pre>
  
  <p>With <code>boost::variant</code> I have begun a variant definition.</p>
  
  <pre><code>typedef boost::variant&lt;Tree&lt;std::string&gt;, Tree&lt;int&gt;&gt; TreeVariant; TreeVariant tree;
  </code></pre>
  
  <p>I know I need to specify a <code>visitor class</code> but it is not clear from <a href="http://www.boost.org/doc/libs/1_53_0/doc/html/variant.html#variant.motivation.solution" rel="nofollow">this example</a> how to define it such that I am able to assign to my <code>tree</code> variable either <code>Tree&lt;std::string&gt;</code> or <code>Tree&lt;int&gt;</code>.</p>
  
  <p>I would then like to proceed from there to call member functions of Tree using the variable <code>tree</code>.</p>