boost Shared_pointer NULL

Yochai Timmer picture Yochai Timmer · Apr 10, 2011 · Viewed 34k times · Source

I'm using reset() as a default value for my shared_pointer (equivalent to a NULL).

But how do I check if the shared_pointer is NULL?

Will this return the right value ?

boost::shared_ptr<Blah> blah;
blah.reset()
if (blah == NULL) 
{
    //Does this check if the object was reset() ?
}

Answer

Ralph picture Ralph · Apr 10, 2011

Use:

if (!blah)
{
    //This checks if the object was reset() or never initialized
}