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() ? } 
                A null shared_ptr does serve the same purpose as a raw null pointer. It might indicate the non-availability of data. However, for the most part, there is no reason for a null shared_ptr to possess a control block or a managed nullptr .
shared_ptr is now part of the C++11 Standard, as std::shared_ptr . Starting with Boost release 1.53, shared_ptr can be used to hold a pointer to a dynamically allocated array. This is accomplished by using an array type ( T[] or T[N] ) as the template parameter.
Use:
if (!blah) {     //This checks if the object was reset() or never initialized } 
                        if blah == NULL will work fine. Some people would prefer it over testing as a bool (if !blah) because it's more explicit. Others prefer the latter because it's shorter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With