title: questions regarding shared_from_this
body: <p>I have a function which takes a <code>shared_ptr&lt;MyClass&gt;</code>.
  In some member function <code>memfun</code> of <code>MyClass</code>, I need to pass <code>this</code> to that function. But if I write</p>
  
  <pre><code>void MyClass:memfun()
  {
     func(shared_ptr&lt;MyClass&gt;(this))
  }
  </code></pre>
  
  <p>I am assuming that after the call has ended the reference count will reach 0 and <code>this</code> will be attempted to be destroyed, which is bad. </p>
  
  <p>Then I remembered that there this class <code>enable_shared_from_this</code> with the function <code>shared_from_this</code>.</p>
  
  <p>So now I am going to use the following:</p>
  
  <pre><code>class MyClass: public enable_shared_from_this&lt;MyClass&gt;
  {
      void MyClass:memfun()
      {
         func(shared_from_this());
      }
  };
  </code></pre>
  
  <p><em><strong>Questions are:</em></strong></p>
  
  <p><strong>1)</strong> Is is absolutely impossible to use the functionality without deriving from <code>enable_shared_from_this</code>?<br>
     <strong>2)</strong> Does deriving from <code>enable_shared_from_this</code> mean that calling memfun on an object with automatic storage duration will result in something bad? E.g.</p>
  
  <pre><code> int main()
   { 
      MyClass m;   //is this OK?
      m.memfun();  // what about this?
   }
  </code></pre>
  
  <p><strong>3)</strong> If I derive from MyClass, will the enable_shared_from_this functionality be correctly inherited or do I need to derive again? That is,</p>
  
  <pre><code>class MyCoolClass: public Myclass
  {
     void someCoolMember
     {
        someCoolFuncTakingSharedPtrToMyCoolClass(shared_from_this());
     }
  }
  </code></pre>
  
  <p>Is this OK? Or correct is the following?</p>
  
  <pre><code> class MyCoolClass: public Myclass, public enable_shared_from_this&lt;MyCoolClass&gt;
      {
         void someCoolMember
         {
            someCoolFuncTakingSharedPtrToMyCoolClass(enable_shared_from_this&lt;MyCoolClass&gt;::shared_from_this());
         }
      }   
  </code></pre>
  
  <p>Thanks very much in advance.</p>