dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #21172
Re: Checking if shared_ptr is NULL
On Tuesday February 1 2011 13:46:55 Anders Logg wrote:
> On Tue, Feb 01, 2011 at 01:36:59PM -0800, Johan Hake wrote:
> > On Tuesday February 1 2011 13:18:54 Anders Logg wrote:
> > > What is the correct way to check whether a shared_ptr is NULL?
> >
> > What with:
> > bool has_child() const
> > {
> >
> > return _child.count()!=0;
> >
> > }
>
> Will try that.
>
> > or just or implement a constructor for Hierarchical which initialize the
> > shared_ptr to 0?
>
> I was under the impression it's always initialized to 0, and
> initialization to zero should be handled by
>
> _foo = shared_ptr<foo>();
Yes you seem to be correct.
From shared_ptr.hpp:
shared_ptr(): px(0), pn() // never throws in 1.30+
{
}
where px is the pointer and pn the count (which is a shared objects in it
self!)
Johan
> --
> Anders
References