title: How to forward an argument to a template member function to a member base class pointer in C++
body: <p>I have a class <code>Foo</code> which uses CRTP to inherit a template method from a parent class and avoid having to provide literally dozens of individual member methods. Something like this:</p>
  
  <pre><code>class Foo : public SomeBarClass&lt;Foo&gt;
  {
  //..
  //from SomeBarClass
  public:
      template &lt;class T&gt; void onMsg(T* msg);
  
  private:
      IFoxMod* foxMod_;
  };
  </code></pre>
  
  <p>Now, in the implementation for <code>onMsg</code>, I would like something like this:</p>
  
  <pre><code>template &lt;class T&gt;
  void Foo::onMsg(T* msg)
  {
      if (foxMod_-&gt;shouldDoStuff(msg))
      {
          //do stuff
      }
  }
  </code></pre>
  
  <p>and there can be many <code>foxMod_</code> types (one of them instantiated in the <code>Foo</code> constructor by name given in config file) as long as they abide by the common interface of providing a <code>bool shouldDoStuff</code> method. The problem, is that this leads me to define the following:</p>
  
  <pre><code>struct IFoxMod
  {
      virtual ~IFoxMod() {}
      template &lt;class T&gt; shouldDoStuff(T* msg) = 0;
  };
  </code></pre>
  
  <p>for all of the <code>FoxMods</code> to implement (like, <code>class redMountainLogic : public IFoxMod</code> might have it's own way of discerning, when it is appropiate to do stuff).</p>
  
  <p>This is illegal though because one cannot have virtual templates and I'm trying to find a workaround for it. Basically, I need to have dynamic dispatch, but the argument I am passing is a template. I can't think of a workaround.</p>