Re: TList question

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Oct 05 1998 - 18:00:29 MEST


Florian Schopper wrote:
> 
> Dear Rooters,
> 
> What is the proper way of calling a member function of an
> Object which is stored in a TList?
> When I call it in the following way, I get an error for all members
> except the last in list.
> 
> .L Det.so
> TList l;
> 
> l.Add(  new MChip() );
> l.Add(  new MChip() );
> l.Add(  new MChip() );
> 
> ( (MChip *) l.At(2) )->NHitHist.Draw(); // The last in list works
> ( (MChip *) l.At(1) )->NHitHist.Draw(); //  gives segmentation violation
> 
> MChip is my own class which includes a Histogram called NHitHist.
> Calling NHitHist.Draw works for all MChip Objects when I don't add them
> to the list.

Florian,
What you do is correct if the objects pointed by the list are
still alive. I have the following suspicion:
In your MChip constructor, you create an histogram (say TH1F).
This histogram is added into the list of objects in current directory.
In the second call to the MChip constructor, in case you create
an histogram with the name, the already existing histogram with
the same name is deleted (in this case you should get a Warning),
but in TList, the first MChip will contain an invalid object NHitHist.
You should do the following in your MChip constructor.
You create the NHitHist object and immediately NHitHist.SetDirectory(0).

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:38 MET