Streamer Question

Hi,

I am using an automatically generated streamer, and it segfaults. I can work around it, but I don’t understand why it is being generated in a particular way, and what the appropriate fix is.

I have a container class Container that inherits publicly from TObject. Container contains a private member pointer to Member_Derived which inherits publicly from an abstract class Member that Inherits publicly from TObject.

Member_Derived::Write works.

Container::Write crashes at TBuffer::WriteObject, and making the pointer to Member_Derived non persistent, ie changing

into

doesn’t produce the crash, but I need to store the object.

If I go into the automatically generated Container::Streamer(TBuffer &R__b) and change the line

to

then everything works. I have noticed that member pointers to native root objects (like TH1F*'s ) always seem to have this upcast in streamers.

Questions: Why does upcasting to TObject work? What would solve this problem without me needing to manually edit the auto-generated root dictionary?

When using the “->” notation in the comment field, you tell ROOT to stream the object assuming that the pointer is NEVER null.

Rene

I realized that Member was inheriting virtually from TObject. Removing virtual seems to have solved the problem, but what if I needed that virtual inheritance? What caused this problem, and how would I solve it properly in general?

Thanks for the reply,

The pointer was definitely not null (I watched it at run time), and upcasting a null pointer shouldn’t fix it anyways.

I think somehow, the streamer of Container didn’t know how to get to the streamer of Member_Derived, but I’m not sure.