Christoph Borgmeier writes: > > my problem is, that I cannot delete the pointers, since the objects do not > own the objects they point to. My test example is > > ---------------------------------------------------------------- > class A: public TObject > { > public: > A(): p1( 0 ), p2( 0 ); > A( A* a, A* b ): p1( a ), p2( b ) {} > ~A(); > A* p1; > A* p2; > > void Print( Option_t * ); > > ClassDef(A,1) > }; > ---------------------------------------------------------------- > > in my main program: > > ---------------------------------------------------------------- > [...] > A* x = new A; > A* y = new A( x, 0 ); > A* z = new A( 0, x ); > A* a = new A( y, z ); > [...] > tree->Branch("Aname","A", &a, 10000, 0 ); > [...] > ---------------------------------------------------------------- > > when I read the event created by this, x is used by y and by z. So if I > delete p1 and p2 in ~A, I get a segmentation violation when z tries to > delete x because it has already been deleted by y. This might seem very > theoretical, but it just happens to be very similar to the structure I use > to store certain decay information. > Hi Cristoph, I suggest you to add a field "DeleteX" to your object, which would be set to 1 by default constructor and to 0 by A( A* a, A* b ), so based on the value of DeleteX the destructor would either delete pointers or not. This solves the problem described above. regards, Pasha.
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:31 MET