Re: [ROOT] dinamic memory allocation within ROOT

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Nov 29 2002 - 21:01:08 MET


Hi Henrique,

You are misusing the operator []. You can do:

TH1D* h = new TH1D()
TObjArray a;
a.Add(h);
a[0]->Draw();
a.At(0)->Draw();

or

TObjArray *b = new TObjArray;
b->Add(h);
b->At(0)->Draw();

Absolutely no need to cast since the objects in the TObjArray
are TObject and there is a TObject::Draw.

Rene Brun



On Fri, 29 Nov 2002, Henrique de M. J. Barbosa - mestrado wrote:

> 
> Hello Rene,
> 
> > At least one advantage of deriving from a common base class TObject.
> > You can do
> >   Histo_List[0])->Draw();
> 
> I tried your example and it doesn't work for me.  Here's what I got:
> 
> root [0] TH1D* h = new TH1D()
> root [1] h->Draw()                                <- this draw is ok
> <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
> root [2] TObjArray *t = new TObjArray()
> root [3] t->GetEntries()
> (const Int_t)0
> root [4] t->Add(h)
> root [5] t->GetEntries()
> (const Int_t)1
> root [6] t[0])->Draw()                            <- this draw is not ok
> !!!Bad command input. Ignored!!!
> root [7] ((TH1D*) t[0])->Draw()                   <- this draw is ok
> 
> Am I missing something?
> 
> thanks,
> 
> Henrique
> ****************************************
> State University at Campinas - BRASIL
> "Gleb Wathagin" Physics Institute
> Department of Cosmic Rays and Chronology
> 
> Henrique Barbosa      The Pierre Auger
> PhD Student             Observatory
> ****************************************
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:21 MET