> From: Thomas Witt [mailto:witt@ive.uni-hannover.de]
>
> Peter,
>
> can you explain why make_shared adds safety. Currently I am
> unable to see why.
> IIUC what happens is a NULL ptr is dereferenced with or
> without make_shared.
> On the first look it seems as if make_shared pretends to be
> safe but isn't.
> When make shared is used the object might be gone already.
>
> Thanks
>
> Thomas

make_shared returns a shared_ptr that may contain a null pointer (thus, the resulting shared_ptr should be tested before use). However, if the returned shared_ptr contains a valid resource, then that shared_ptr can be safely used because the reference count has been increased. That's not true for weak_ptr, and that's why make_shared (and the constructor for shared_ptr taking a weak_ptr as an argument) adds safety.

Bjorn Karlsson