title: factory of templated class
body: <p>I'm not sure how to accomplish this in c++, but I want to prevent users of my library from providing singleton objects when I request a certain kind of object from their plugin that leverages my core libraries.  I've tried a bunch of variations, but this is my current attempt at an implementation at a templated factory in C++.</p>
  
  <p>Questions are embedded as comments in FooProvider.h stub.  Thanks!</p>
  
  <pre><code>/*
   * IFooProvider.h
   */
  //Interface - Factory for different variations of IFoo
  class IFooProvider
  {
      virtual std::shared_ptr&lt;IFoo&gt; getProvidedFoo();
  }
  
  //===========================================================================
  
  /*
   * FooProvider.h
   */
  template &lt;typename T&gt; //Not sure how to enforce that T is derived from IFoo?
  class FooProvider : public IFooProvider
  {
      std::shared_ptr&lt;IFoo&gt; getProvidedFoo()
      {
          //This doesn't work.
          //Not sure how to perform this cast or if this is even possible?
          std::shared_ptr&lt;IFoo&gt; rtn = std::make_shared&lt;T&gt;();
          return rtn;
      }
  }
  
  //===========================================================================
  
  //Other team's implementation version.  Exists in a different library that I have no control over.
  
  /*
   * MyFooProvider.h
   */
  class MyFooProvider : public FooProvider&lt;MyFoo&gt;
  {
      //Nothing really going on here.  Just want to implement a provider for MyFoo
  }
  
  //===========================================================================
  </code></pre>