Re: Streamers and pointers to data members

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Wed, 26 Nov 2008 08:27:37 -0600


 > So my question is, do I always need to set pointers to zero in default constructors, or have I run into a bug?

Yes you must initialize all members of your class in your default constructors (and especially the pointers); Otherwise you class is a mal-formed C++ class (i.e. this is required with or without ROOT).

Cheers,
Philippe.

Philip Rodrigues wrote:
> Hi roottalk,
> I have a class with a data member which is a pointer to a TH2F. I can
> successfully stream it to disk, but when I read it back, I get a
> crash. The crash goes away if I set the TH2F pointer to zero in the
> default constructor. (The attached file contains a minimal example -
> run the "testrun.C" macro).
>
> So my question is, do I always need to set pointers to zero in default
> constructors, or have I run into a bug? I couldn't see any mention of
> this in the documentation.
>
> Thanks,
> Philip
Received on Wed Nov 26 2008 - 15:27:52 CET

This archive was generated by hypermail 2.2.0 : Wed Nov 26 2008 - 17:50:02 CET