title: Why shared_from_this can't be used in constructor from technical standpoint?
body: <p>In <a href="https://rads.stackoverflow.com/amzn/click/com/0321623215" rel="noreferrer" rel="nofollow noreferrer">the book <em>The C++ Standard Library</em></a> at page 91 I have read this about <code>shared_from_this()</code>:</p>
  
  <blockquote>
    <p>The problem is that <code>shared_ptr</code> stores itself in a private member of
    <code>Person</code>’s base class, <code>enable_shared_from_this&lt;&gt;</code>, <strong>at the end</strong> of
    the construction of the Person.</p>
  </blockquote>
  
  <p>The relevant code snippet from the book is:</p>
  
  <pre><code>class Person : public std::enable_shared_from_this&lt;Person&gt; {
     ...
  };
  </code></pre>
  
  <p>I don't understand two things here: </p>
  
  <ol>
  <li>who is this <code>shared_ptr</code> which stores itself?</li>
  <li>how he can store itself anywhere at the end of the construction of <code>Person</code>? I think construction of <code>Person</code> ends up with the last statement of its constructor which written by me.</li>
  </ol>
  
  <p>I understand that there is <code>weak_ptr</code> which hasn't been initialized yet.</p>
  
  <p>EDIT:
  Thanks to Angew! <code>shared_from_this</code> will work only after first <code>shared_ptr</code> to <code>Person</code> was created. This <code>shared_ptr</code> will check if <code>Person</code> class inherited from <code>enable_shared_from_this</code>, and if yes then initialize its internal <code>weak_ptr</code>.</p>