Re: [ROOT] new operator

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Mar 21 2001 - 11:36:12 MET


Hi Thomas,

In the statement new (a[2]) myClass that you must use to enter a new object
in a TClonesArray, the operator "new with placement" is used.
a[2] is used as an input parameter returning the pointer to a possible existing
object at this slot. If an object already exists, the new operator does not
allocate a new block of memory. The Myclass constructor will simply overwrite
the previous object definition at this address.
If the pointer a[2] is null, this special new operator allocates space
for a new object that you can later retrieve via a[2].

Rene Brun

Thomas Bretz wrote:
> 
> Hello all,
> 
> I found in the description of TClonesArray the following statement about
> the index-operator:
> 
> This operator should not be used for
> lefthand side assignments, like a[2] = xxx. Only like,
> new (a[2]) myClass, or xxx = a[2].
> 
> Whats the differents between
> a[2] = new myClass and
> new (a[2] myClass?
> 
> Thanks,
> Thomas.



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:40 MET