Modify

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:

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!

Attachments (0)

Change History (3)

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

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 Changed 6 years ago by m_albert137@…

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 Changed 6 years ago by chris_kohlhoff

Resolution: invalid
Status: newclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain chris_kohlhoff.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.