Opened 6 years ago

Closed 6 years ago

#6941 closed Bugs (invalid)

ASIO Daytime.3 example misuses enable_shared_from_this

Reported by: m_albert137@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.49.0 Severity: Problem
Keywords: Cc:


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

return pointer( new tcp_connection....)

where pointer is a typedef for the shared_ptr type.


return (new tcp_connection...).shared_from_this()


By the way, thanks for all the wonderful software!

Change History (3)

comment:1 in reply to:  description Changed 6 years ago by Steven Watanabe

Replying to m_albert137@…:


return (new tcp_connection...).shared_from_this()


That's illegal. shared_from_this only works after you've created the initial shared_ptr.

comment:2 Changed 6 years ago by m_albert137@…

My apologies.... I missed that point.

Also, it makes sense that the c'tor is private and the factory forces the construction of the shared pointer.

Thank you.

comment:3 Changed 6 years ago by chris_kohlhoff

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.