Re: Streamers and pointers to data members

From: Philip Rodrigues <p.rodrigues1_at_physics.ox.ac.uk>
Date: Wed, 26 Nov 2008 15:01:24 +0000


OK, this sounds fairly unanimous - I'll make sure to do this in future. In my defence, I never use the default constructor - it's there solely for the benefit of the ROOT streamer, so I never use the values it sets.

Thanks,
Philip

Rene Brun wrote:

> Yes, you MUST set to 0 all your pointers in the default constructor.
> By the way see interesting option -Weffc++ (from Scott Myers book), this 
> will tell you what you are doing wrong in your constructors ::)
> 
> Rene brun
> 
> 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 - 16:01:30 CET

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