class classA: public TNamed
{
public:
classA();
unsigned int n;
unsigned int * p;
void Do();
ClassDef(classA, 1)
};
When writing a class object to a root file I would like a deep copy of pointer members (unsigned int *p). When reading the object of a class from a Root file I would like the contents of memory pointed to by the pointers restored.
How can I achieve that? Can you provide a simple example for the case of the unsigned int *p member of classA?
That works.
But the inevitable question that will get asked is what if one has used a new[] operator on p and the number of elements is some arbitrary integer?
I forgot to mention that βnβ also need to have its type changed to βintβ (the internal of the I/O currently assume this type).
Well (I assumed that the new operator was called but that the argument was stored in βnβ), the I/O must have some way of knowing the number of elements that should be stored, having a data member holding this information is the option we are supporting
And how to handle the case of STL containers containing pointers, e.g. vector<double *> vp;
vector of pointers are only supported when the pointee is a class and points to a single element. For anything else use nested vectors. e.g. vector<vector<double> > vp;
If you want to store instances of a class in a ROOT file, that class need to have a ROOT dictionary. The sole expection is STL containers (themselves, not their) content that are stored as part of a class that has a dictionary. In this case, the dictionary for the STL collection is made automatically. For example for
class A {
std::vector<B> fB;
std::vector<C*> fC;
std::vector<std::vector<double> > fD;
};
You need to explicitly request the dictionary fo A, B and C.