title: So I can't dynamic_cast< functionPointer >( ((void*)(myFuncPtr)) )? What should I do?
body: <p>I have a base class, Parameter, and two derived classes: Scalar &amp; Vector.  In each derived class, I have a member function which takes a function pointer as input:</p>
  
  <p>In the Scalar class:</p>
  
  <pre><code>typedef double (*samplerType)(RandNum&amp; rnState);
  void RegisterSampler( samplerType input );
  </code></pre>
  
  <p>In the Vector class:</p>
  
  <pre><code>typedef std::vector&lt;double&gt; (*samplerType)(RandNum&amp; rnState);
  void RegisterSampler( samplerType input );
  </code></pre>
  
  <p>Note the different return types: <code>double</code> and <code>std::vector&lt;double&gt;</code>.  I would like to define this function within the mutual base class, Parameter -- so I changed the functions to take <code>(void* input)</code> and then tried the following when defining the functions within the Scalar &amp; Vector classes:</p>
  
  <p>samplerType inputSampler = dynamic_cast&lt; samplerType >(input);</p>
  
  <p>However, I get the following error in VS 2005:</p>
  
  <pre><code>error C2680: 'double (__cdecl *)(RandNum &amp;)' : invalid target type for dynamic_cast
  target type must be a pointer or reference to a defined class
  </code></pre>
  
  <p>Grumble Grumble Grumble...  I'm not sure if this is valid (standard permitting) C++ or not, but I guess either way I'll treat this as a flaw in my design.</p>
  
  <p><strong>So</strong>, My standard approach would be to template the base class with the return type of the function, but I can't.  The base class, Parameter, must -- by design -- be free of all type information.  <strong>Is there a different way to design the inheritance?</strong></p>
  
  <p>My attempts to Google this have turned up virtually nil on function pointers -- Hence I'll believe that this is in fact <em>invalid syntax</em>, but perhaps just a <em>really, really</em> uncommon design challenge? <strong>Is this another one of those places, <em>functors</em> to the rescue?</strong></p>