title: Is it OK to use reference to the object owned by a shared_ptr?
body: <p>I found this is working well but don't know if this is safe as I don't understand why it works:</p>
  
  <pre><code>struct X{
    static X&amp; make(){
      return *std::make_shared&lt;X&gt;();
    }
    ...
  }
  
  int main(){
     const auto&amp; a = X::make();
     a.function();
     ...
     // seems like the instance holds and nothing broken
  }
  </code></pre>
  
  <p>In my understanding, the returned reference to the derefed object out of <code>shared_ptr</code> <code>operator*</code> should not impact how <code>shared_ptr</code> manages the instance's reference count: so the created instance inside <code>make()</code> should be destroyed after <code>make()</code> is done. But this pattern of code has been working well for many times and I don't see why. So I'm not sure if we can really do it in this way... appreciate any comments!</p>