title: How to deal with smart_ptr when class method returns reference
body: <p>In my project i would like to use smart_ptrs instead of raw pointers.
  Now if a class method returns a pointer to itself, how can i deal with this using smart_pointers correctly?</p>
  
  <pre><code>class bar{
  public:
      std::shared_ptr&lt;bar&gt; foo(){std::shared_ptr&lt;bar&gt;(this);}
  };
  
  int main()
  {
      auto a = std::make_shared&lt;bar&gt;();
      auto b = a-&gt;foo();
      std::cout &lt;&lt; a.use_count() &lt;&lt; std::endl; //outputs 1 
  }
  </code></pre>