|
Boost Users : |
From: Stephen Torri (storri_at_[hidden])
Date: 2007-05-17 11:18:39
On Thu, 2007-05-17 at 16:59 +0200, Leon Mlakar wrote:
> > Now I am trying to be a good programmer and keep track of my pointers.
> > So I decided that I should replace the pointer with a shared_ptr.
> >
> > In regards to the validity of calling get() on an unassigned
> > shared_ptr I thought that if a shared_ptr was declared in the
> > header and no call is given to any constructor that the
> > default constructor would be used.
> > Therefore the shared_ptr would have a value of 0x0.
>
> It would, and you shouldn't get the message. Perhaps the message comes from
> the copy assignment (which again, it shouldn't) - try
>
> m_instance.reset(new Trace_State());
>
> instead.
>
> You could also simply write if (!m_instance) as shared_ptr declares operator
> ! just for this purpose.
>
> But I agree, in a singleton pattern you benefit from shared pointer only if
> the singleton lives shorter than the application and you want to make sure
> it's not gone while still in use.
>
> Leon
Since its suppose to live the length of the application then its alright
that we make it follow the Meyers Singleton without using the boost
shared_ptr. Thanks for the help.
Stephen
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net