Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::enable_shared_from_this why?
From: Igor R (boost.lists_at_[hidden])
Date: 2009-01-15 07:27:01


>
> Anyway, which is the reason to access a variable through a member
> function if you can get the variable directly anyway? Or is there any case
> where you can't?
>

The code you quoted is just trivial example of "how to use
shared_from_this()", not "why to use it".
If you want to realise *why* such a feature can be useful, look, for
instance, at ASIO examples:
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/tutorial/tutdaytime3.html
Actually, there're lots of cases where you might want to make shared_ptr of
"this" inside a member function.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net