This is a strange angle to the behavior of shared_ptr . It has a constructor that allows you to do shared_ptr , which owns something, and points to something else:
template< class Y > shared_ptr( const shared_ptr<Y>& r, T *ptr );
shared_ptr built using this constructor has ownership of r , but indicates what ptr points to (i.e., calling get() or operator->() will return ptr ). This is convenient for cases when ptr points to a subobject (for example, a data element) of an object belonging to r .
On the page with which you are linking calls, shared_ptr , which has nothing empty, and shared_ptr , which indicates nothing (i.e. whose get() == nullptr ) is null. (Empty is used in this sense by standard, null is not.) You can build empty, but not empty shared_ptr , but it will not be very useful. An empty but not null shared_ptr is essentially a non-owning pointer that can be used to do some strange things, such as passing a pointer to something allocated on the stack, to a function that expects shared_ptr (but I would suggest punching the one who first puts shared_ptr in the API).
boost::shared_ptr also has this constructor , which they call the alias constructor.
TC Sep 18 '14 at 19:23 2014-09-18 19:23
source share