Deep copy of TObjString (or any TObject's subclass)

Dear all,

I try to make a deep copy of a TObject’s subclass. The pointer to the destination object should not be changed. I thought the method “Copy()” was made for that. However :

root [0] TObject *s = new TObjString("asdf")
root [1] TObject *s2 = new TObjString("new")
root [2] s2->Copy(*s)
root [3] cout << ((TObjString*)s)->GetString()->Data() << endl;
asdf

Please note that it works for TH1F because Copy is overwritten.

How can I achieve this ?
Shouldn’t Copy be implemented in TObjString (and any other subclass of TObject) ?
Ideall

Thanks in advance,
Barth

Hi,

you can use Clone():

TObject *s = new TObjString("asdf") TObString *s2 = (TObString*)s->Clone(); s2->GetString().Data()

Cheers, Axel.

Yes it is what I was now considering.

Thanks,
Barth