title: Subclass of class that inherits from enable_shared_from_this returning shared_ptr of self
body: <p>I'm wondering if there is anyway to do something like this pseudo code:</p>
  
  <pre><code>class A : public std::enable_shared_from_this&lt;A&gt; {
      public:
          std::shared_ptr&lt;self_t&gt; getPtr(){
              return std::static_pointer_cast&lt;self_t&gt;(shared_from_this());
          }
  };
  
  class B : public A {
      std::vector&lt;A&gt; container;
  
      std::shared_ptr&lt;self_t&gt; addChild(A child){
          container.push_back(child);
          return getPtr();
      }
  };
  
  class C : public B {
      public:
          std::shared_ptr&lt;self_t&gt; doSomething(){
              // something
              return getPtr();
          }
  };
  
  int main(){
      A obja = new A();
      C obj = new C();
      obj-&gt;addChild(obja)-&gt;doSomething()
  }
  </code></pre>
  
  <p>My goal is that an object represents a view (as in the V in MVC), and for methods to be able to return itself for chained calling. Eg: <code>-&gt;setTop(0)-&gt;addChild(child1)-&gt;setBottom(0)</code>.</p>
  
  <p>I've read that it may be more approachable to do something like overloading the <code>&lt;&lt;</code> operator, but I don't see that working to well or looking very pretty.</p>
  
  <p>One thought I had was to make a macro called <code>VIEW(name,parent)</code> that would use templates to expand out, but I had issue with self-refferental default template arguments.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>-- edit --</p>
  
  <p>In a nut shell, I'm hoping to have a base class inherit from <code>enable_shared_from_this</code>. The base class would have a method such as <code>doSomething</code> that returns the shared pointer. When a derived class inherits from the base class, I want the <code>doSomething</code> method to return a shared pointer to the derived class. I want to be able to do this without overriding <code>doSomething</code> in the derived class.</p>