Hi Isi, This will work, but I would not recommend this approach. Note that if you insert histPtr in a ROOT collection TList, TObjArray, etc if you call list->Delete(), the collection classes check if the object is on heap or not. If it is not in the heap, the object is simply removed from the list and it is not deleted. Rene Brun Isard_Dunietz wrote: > > // Is the following code fragment reasonable, when one is not sure whether > // an object was newed or not: > > TH1F hist( "hist", "",...); > bool condition = ...; > TH1F * histPtr( condition ? new TH1F(...): &hist ); > > // use histPtr as much as needed > > //Once done with histPtr, maybe the easiest to do is just to say > if ( histPtr->IsOnHeap() ) > delete histPtr; > // else histPtr not on the heap and we are fine as the dtor will take of > // it automatically > > Thank you for your advice. Best, Isi
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:05 MET