title: Can you use CRTP and functions taking an interface as a parameter?
body: <p>In C++ pure virtual classes are often used for runtime polymorphism.</p>
  
  <p>So you have:</p>
  
  <pre><code>class IInterfaceA
  {
      virtual void DoFoo() = 0;
  };
  </code></pre>
  
  <p>And derived classes like:</p>
  
  <pre><code>class CFancyObject : public IInterfaceA
  {
  ...
  </code></pre>
  
  <p>Which then can be used in functions like:</p>
  
  <pre><code>void Foo(IInterfaceA &amp;interface);
  </code></pre>
  
  <p>But this is runtime case, and if the objects are known at compile time, we can do better by using CRTP:</p>
  
  <pre><code>template&lt;class T&gt; class IInterfaceA
  {
  public:
      void DoFoo()
      {    
          static_cast&lt;T*&gt;(this)-&gt;CallDerivedFunction();
      }
  }
  
  class CFancyObject : public IInterfaceA&lt;CFancyObject&gt;
  {
      ...
  }
  </code></pre>
  
  <p>Is it possible to use CRTP based derived classes in functions that take IInterface as a parameter?</p>
  
  <pre><code>void Foo(IInterfaceA&lt;?&gt; &amp;interface);
  </code></pre>