Hi Dario,
Do:
DataCh *dino = (DataCh*)gino->At(i);
Rene Brun
Dario.Motta@mpi-hd.mpg.de wrote:
>
> Hi rooters,
> I apologize in advance for my stupid question: I'm very new either in ROOT
> and in C++ and I'm myself surprised already how far I could nevertheless
> move...
>
> I've defined my "Event" class, which contains (among the others) a
> TClonesArray of the class "DataCh", which I also defined and implemented.
> The class "Event" has a GetDataCh() function, which simply returns
> the pointer to the TClonesArray member:
>
> ------------------------------------------
> class Event: public TObject {
>
> private:
> (...)
> TClonesArray *fDataCh;
> (...)
> public:
> (...)
> TClonesArray *GetDataCh() const {return fDataCh;}
> (...)
> };
> --------------------------------------------
> In the constructor of the Event class, the TClonesArray is created as
> follows (I used the "Event.cxx" in the test directory as a model):
>
> --------------------------------------------
> if(!fgDataChs) fgDataChs=new TClonesArray("DataCh",32);
> fDataCh=fgDataChs;
> --------------------------------------------
>
> Now, since I want to make sure I'm correctly filling my objects, I would
> like to get the data members of the single array elements of "fDataCh".
>
> Hence in my 'main' I wrote:
>
> --------------------------------------------
> (...)
> TClonesArray *gino=new TClonesArray("DataCh",32); //I create a "copy" array
> gino=event->GetDataCh(); //I assign the copy to the actual member of 'event'
> (...)
> DataCh dino = *(gino+i); //I try to assign the 'ith' element to a DataCh object
> (...)
> --------------------------------------------
>
> At compile time I get the following error message for the last command:
>
> "cannot convert `TClonesArray' to `DataCh' in initialization"
>
> from which I understand I could have casting problems...
>
> Why can't I access directly the elements of my TClonesArray, which has
> been defined to contain "DataCh" objects?
>
> What's the right way to pick up and copy a single object in a TClonesArray?
>
> Thank you very much for the help...
>
> Best regards,
> Dario Motta
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:43 MET