title: Using make_shared with a protected constructor + abstract interface
body: <p>Given an abstract interface and an implementation derived from that interface, where constructors are protected (creation of these objects only being available from a class factory - to implement a DI pattern), how can I make use of make_shared in the factory function?</p>
  
  <p>For example:</p>
  
  <pre><code>class IInterface
  {    
  public:    
      virtual void Method() = 0;
  };
  
  class InterfaceImpl : public IInterface
  {
  public:
      virtual void Method() {}
  
  protected:    
      InterfaceImpl() {}    
  };
  
  std::shared_ptr&lt;IInterface&gt; Create()
  {
      std::shared_ptr&lt;IInterface&gt; object = std:: make_shared&lt;InterfaceImpl&gt;();    
      return object;
  }
  </code></pre>
  
  <p>make_shared obviously cannot access the protected constructor in InterfaceImpl, or indeed in IInterface, giving me the following error</p>
  
  <pre><code>
  error C2248: 'InterfaceImpl::InterfaceImpl' : cannot access protected member declared in class 'InterfaceImpl'
  </code></pre>
  
  <p>So reading here (question: <a href="https://stackoverflow.com/questions/3378520/how-to-make-boostmake-shared-a-friend-of-my-class">How to make boost::make_shared a friend of my class</a>), I tried putting the following into the implementation class:</p>
  
  <pre><code>
  friend std::shared_ptr&lt;InterfaceImpl> std::make_shared&lt;InterfaceImpl>();
  </code></pre>
  
  <p>It still wouldn't compile.  So then I put another one into the IInterface class too.  Still no joy.  What have I done wrong here?  </p>
  
  <p>EDIT: Full source file used to compile, with "friend"...</p>
  
  <pre><code>#include &lt;memory&gt;
  
  class IInterface
  {    
  public:    
      friend std::shared_ptr&amp;lt;IInterface&gt; Create();     
      virtual void Method() = 0;
  };
  
  class InterfaceImpl : public IInterface
  {    
  public:     
      virtual void Method() {}
  
  protected:    
      friend std::shared_ptr&amp;lt;IInterface&gt; Create();     
      InterfaceImpl() {}    
  };
  
  std::shared_ptr&lt;IInterface&gt; Create()
  {
      std::shared_ptr&lt;IInterface&gt; object = std::make_shared&lt;InterfaceImpl&gt;();    
      return object;
  }
  
  void main()
  {
      std::shared_ptr&lt;IInterface&gt; i = Create();   
  }
  </code></pre>