Copy constructors

From: Stefano Bettelli (bettelli@tn.infn.it)
Date: Tue Sep 14 1999 - 15:22:50 MEST


Hi ROOTers,
does anybody know how to copy an object like a
TDirectory with lots of internal pointers without
an appropriate copy constructor (or assignement
operator)? For instance:

TGeometry *g, *new_g;                   // geometry pointers
< ... load a directory in dir ... >
g = (TGeometry *)(dir->Get("MYGEOM"));  // get a geometry
new_g = new TGeometry(*g);              // try to build a copy
< ... work on new_g ... >
delete new_g;                           // get rid of the copy
g = (TGeometry *)(dir->Get("MYGEOM"));  // try to build a fresh copy but ...
new_g = new TGeometry(*g);              // ... this gives segmentation violation

This happens (I figure out) because the destructor of a
TGeometry takes care to deallocate some objects which 
won't be referenceable any more by the original TGeometry.
Is it a feature? (not to have copy constructors or assignement
operators I mean).

----------------------------------------------------------
E-Mail: Stefano Bettelli <bettelli@tn.infn.it>
WWW   : http://meitner.tn.infn.it



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:39 MET