title: How to initialize a shared_ptr that is a member of a class?
body: <p>I am not sure about a good way to initialize a <code>shared_ptr</code> that is a member of a class. Can you tell me, whether the way that I choose in <code>C::foo()</code> is fine, or is there a better solution?</p>
  
  <pre><code>class A
  {
    public:
      A();
  };
  
  class B
  {
    public:
      B(A* pa);
  };
  
  class C
  {
      boost::shared_ptr&lt;A&gt; mA;
      boost::shared_ptr&lt;B&gt; mB;
      void foo();
  };
  
  void C::foo() 
  {
      A* pa = new A;
      mA = boost::shared_ptr&lt;A&gt;(pa);
      B* pB = new B(pa);
      mB = boost::shared_ptr&lt;B&gt;(pb);
  }
  </code></pre>