Boost logo

Boost :

From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2008-04-16 17:16:18


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 16 April 2008 15:46 pm, Daniel Frey wrote:
> The problem can be solved by either extending or modifying the
> interface: When we add the following method(s):
>
> template< typename U >
> shared_ptr<U> shared_from_this( U* u );
>
> template< typename U >
> shared_ptr<U const> shared_from_this( U const* u );
>
> it's then possible for a method of T to call shared_from_this(this)
> instead of shared_from_this() to gain a shared_ptr<T>.
>
> Additionally, the interface is generally useful, as it could be called
> with other pointers, e.g. to sub-objects (member variables) of T. It's
> IMHO a nice match to the shared_ptr-constructor which takes a shared_ptr
> and an additional plain pointer.

Wouldn't it be safer to make it a non-template? The aliasing constructor can
be easily misused. If the user really wants to use the aliasing constructor,
they could always pass the return value from shared_from_this() to the
aliasing constructor.

- --
Frank
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIBmyj5vihyNWuA4URAs0ZAJ466WCMmJ5EZz98n8su/1+IYJ4MyACeOtMg
ExRZ6AWIn6SQHOmfDAWjnV8=
=gKNc
-----END PGP SIGNATURE-----


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk