Boost logo

Boost Users :

From: Thore Karlsen (sid_at_[hidden])
Date: 2005-07-30 21:32:09

On Sat, 30 Jul 2005 21:55:56 -0400 (EDT), Merrill Cornish
<merrill.cornish_at_[hidden]> wrote:

>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

A default constructed smart pointer is initialized to 0. You can get the
raw pointer with operator get():

  if (!mParent.get())
     ... uninitialized

To set it to 0, use reset():


Be seeing you.

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