title: Factory returning boost::visitor objects
body: <p>I wish to create a visitor factory, which returns an object of either of these types:</p>
  
  <pre><code>class Visitor1: public boost::static_visitor&lt;int&gt;
  {
  public:
      int operator()(int&amp; ) const 
      {
          return 1;
      }
  
      int operator()(bool&amp; ) const 
      {
          return 1;
      }
  };
  
  class Visitor2: public boost::static_visitor&lt;int&gt;
  {
  public:
      int operator()(int&amp; ) const 
      {
          return 2;
      }
  
      int operator()(bool&amp; ) const 
      {
          return 2;
      }
  };
  </code></pre>
  
  <p>I presumed that I could return a pointer of type boost::static_visitor* for the object created by the factory, but this doesn't compile. Nor can I have a reference to the object, as follows:</p>
  
  <pre><code>Visitor1 v;
  Type t;
  boost::static_visitor&lt;int&gt;&amp; vR = v;
  boost::apply_visitor(vR, t);
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>see reference to function template instantiation 'int boost::apply_visitor&lt;boost::static_visitor&lt;R&gt;,Type&gt;(Visitor &amp;,Visitable &amp;)' being compiled
  1&gt;          with
  1&gt;          [
  1&gt;              R=int,
  1&gt;              Visitor=boost::static_visitor&lt;int&gt;,
  1&gt;              Visitable=Type
  1&gt;          ]
  1&gt;c:\boost_1_49_0\boost\variant\variant.hpp(858): error C2064: term does not evaluate to a function taking 1 arguments 
  </code></pre>
  
  <p>How should I implement my factory?</p>