Boost logo

Boost Users :

From: Merrill Cornish (merrill.cornish_at_[hidden])
Date: 2005-07-30 20:55:56

I'm running Boost 1.32.0 under MinGW, so NULL is 0 rather than (void*)0.

While I understand what smart pointers are all about, this is the first time I've tried converting code with conventional pointers to use smart pointers. My original application had class data members such as

     Node *mParent;

which were initialized to NULL in the class constructor initialization lists. Later, the data members were assigned pointers to real Node objects. In particular, the application needs at various times to detect whether the data member is NULL or a "real" node and to occassionally set real nodes to NULL.

OK, now I'm trying to convert to shared_ptrs. So, I have a typedef for notation convenience:

     typedef boost::shared_ptr<Node> NodePtr;

The class data member declaration now looks like

     NodePtr mParent;

but, how do I initialize it to NULL? In the smart pointer world *is* there such a thing as a generic NULL that can be assigned to all smart pointers. Or, will I need something like

     NodePrt NullNodePtr; // never initialized

then assign

    mParent = NullNodePtr;

This would mean that I would been a NullXPtr for every smart pointer type X I have. If that's the way it must be, then OK, but I would like to know how things are supposed to be done.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at