Hi Andre, I tried your example on version 2.25.02 and i got an error message at event 1: filling in 20 events Event 0 Event 1 Error in <TArrayD::operator[]>: index 1 out of bounds (size: 0, this: 0x4027c418) I don't understand why, but eliminating the paranthesis in the line (*mass_values)[i] = 0; => *mass_values[i] = 0; it works. S.b can explain the reason please? I have a related question about TArrays: In this example, I'd declare TArrayD instead of TArrayD* as follows in order to simplify. Is it a bad idea? class ClDrawer { public: ClDrawer(); private: int num_events; // number of selected events TArrayD mass_values; // mass points }; ClDrawer::ClDrawer() { num_events = 20; mass_values.Set(num_events); printf("filling in %d events\n",num_events); int i; for (i=0; i<num_events; ++i) { printf(" Event %d\n",i); mass_values[i] = 0; } printf("done filling\n"); } Cheers Denis ------------------------------------------------------------------------ Istituto Nazionale di Fisica Nucleare | Office: A 39 Via Pietro Giuria, 1 | Phone: (+39)011-6707377/7359 I-10125 TORINO (Italy) | Fax: (+39)011-6699579 ------------------------------------------------------------------------ at Cern: office 160-R-030, phone (+41)22-7672917/72918 ------------------------------------------------------------------------ On Sun, 26 Nov 2000, Andre Holzner wrote: > Hello, > > maybe this is a trivial question. I'm using root 2.26/00 of 7 November > 2000 > on Linux. > > I have a file ClDrawer.C: > > #include <TArrayD.h> > > class ClDrawer > { > public: > ClDrawer(); > > int num_events; // number of selected events > > TArrayD *mass_values; // mass points > > > }; > > //---------------------------------------------------------------------- > > ClDrawer::ClDrawer() > { > num_events = 20; > > mass_values = new TArrayD(num_events); > mass_values->Set(num_events); > > printf("filling in %d events\n",num_events); > > int i; > for (i=0; i<num_events; ++i) > { > printf(" Event %d\n",i); > (*mass_values)[i] = 0; > } > > printf("done filling\n"); > } > > > After starting root, I run > > root [0] .L ClDrawer.C > root [1] ClDrawer *cldrawer = new ClDrawer; > filling in 20 events > Event 0 > Event 1 > done filling > root [2] > > i.e. the loop stops after the second event instead of filling in all 20. > > If I comment out the line > (*mass_values)[i] = 0; > > > I get the output up to Event 19. > > > What am I doing wrong ? > > > > thanks, > > > Andre > > > -- > ------------------+---------------------------------- > Andre Holzner | +41 22 76 76750 > Bureau 32 2-C13 | Building 32 > CERN | Office 2-C13 > CH-1211 Geneve 23 | http://wwweth.cern.ch/~holzner/ >
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:38 MET