Opened 10 years ago

Closed 10 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:

Description

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.

Perhaps:

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

?

By the way, thanks for all the wonderful software!

Change History (3)

in reply to:  description comment:1 by Steven Watanabe, 10 years ago

Replying to m_albert137@…:

Perhaps:

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 by m_albert137@…, 10 years ago

My apologies.... I missed that point.

http://en.cppreference.com/w/cpp/memory/enable_shared_from_this

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

Thank you.

comment:3 by chris_kohlhoff, 10 years ago

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