Boost C++ Libraries: Ticket #6941: ASIO Daytime.3 example misuses enable_shared_from_this https://svn.boost.org/trac10/ticket/6941 <p> In the documentation for the ASIO library, the Daytime.3 example has class tcp_connection inheriting from enable_shared_from_this, but then in "tcp_connection::create()" we have </p> <blockquote> <p> return pointer( new tcp_connection....) </p> </blockquote> <p> where pointer is a typedef for the shared_ptr type. </p> <p> Perhaps: </p> <blockquote> <p> return (new tcp_connection...).shared_from_this() </p> </blockquote> <p> ? </p> <p> By the way, thanks for all the wonderful software! </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6941 Trac 1.4.3 Steven Watanabe Thu, 24 May 2012 22:38:36 GMT <link>https://svn.boost.org/trac10/ticket/6941#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6941#comment:1</guid> <description> <p> Replying to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6941" title="#6941: Bugs: ASIO Daytime.3 example misuses enable_shared_from_this (closed: invalid)">m_albert137@…</a>: </p> <blockquote class="citation"> <p> Perhaps: </p> <blockquote> <p> return (new tcp_connection...).shared_from_this() </p> </blockquote> <p> ? </p> </blockquote> <p> That's illegal. shared_from_this only works after you've created the initial shared_ptr. </p> </description> <category>Ticket</category> </item> <item> <author>m_albert137@…</author> <pubDate>Thu, 24 May 2012 23:16:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6941#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6941#comment:2</guid> <description> <p> My apologies.... I missed that point. </p> <p> <a class="ext-link" href="http://en.cppreference.com/w/cpp/memory/enable_shared_from_this"><span class="icon">​</span>http://en.cppreference.com/w/cpp/memory/enable_shared_from_this</a> </p> <p> Also, it makes sense that the c'tor is private and the factory forces the construction of the shared pointer. </p> <p> Thank you. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Mon, 28 May 2012 23:27:30 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6941#comment:3 https://svn.boost.org/trac10/ticket/6941#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> Ticket