title: Use case of shared_from_this and this
body: <p>In <a href="http://www.boost.org/doc/libs/1_65_1/doc/html/boost_asio/tutorial/tutdaytime7/src.html" rel="nofollow noreferrer">this source file</a> there are two classes : <code>tcp_connection</code> and <code>tcp_server</code>. I've seleceted the relevant bits of code in my opinion but you might want to refer to the full source code for more information.</p>
  
  <pre><code>class tcp_connection : public boost::enable_shared_from_this&lt;tcp_connection&gt;
  {
  public:
    typedef boost::shared_ptr&lt;tcp_connection&gt; pointer;
  
    void start()
    {
      message_ = make_daytime_string();
  
      boost::asio::async_write(socket_, boost::asio::buffer(message_),
          boost::bind(&amp;tcp_connection::handle_write, shared_from_this()));
    }
  };
  
  class tcp_server
  {    
  private:
    void start_accept()
    {
      tcp_connection::pointer new_connection =
        tcp_connection::create(acceptor_.get_io_service());
  
      acceptor_.async_accept(new_connection-&gt;socket(),
          boost::bind(&amp;tcp_server::handle_accept, this, new_connection,
            boost::asio::placeholders::error));
    }
  };
  </code></pre>
  
  <p>My question is simple : what would we use <code>shared_from_this</code> as a <code>bind</code>argument within the <code>async_write</code> function and use <code>this</code> as a <code>bind</code>argument within the <code>
  async_accept</code>function? </p>