title: Interface pattern with shared_ptr
body: <p>I want to have the following class structure:</p>
  
  <pre><code>#include &lt;tr1/memory&gt;
  
  class Interface;
  class Impl;
  
  class Impl
  {
  public:
      Impl( std::tr1::weak_ptr&lt; Interface &gt; interface );
  
  private:
      std::tr1::weak_ptr&lt; Interface &gt; interface_;
  };
  
  class Interface
  {
  public:
      Interface() { impl_ = new Impl( this ); }
  
  private:
      std::tr1::shared_ptr&lt; Impl &gt; impl_;
  };
  
  Impl::Impl( std::tr1::weak_ptr&lt; Interface &gt; interface )
          : interface_(interface)
  {}
  </code></pre>
  
  <p>The code doesn't work since a weak_ptr can only be constructed from a shared_ptr. I can't construct a shared_ptr of this in the ctor since it would destroy the object when leaving the ctor.</p>
  
  <p>The interface will be held as a shared_ptr by the caller. The Implementation needs to be shared_ptr since its lifetime is longer than the Interface lifetime. </p>
  
  <p>Is there an elegant way to establish this relationship?</p>