Dynamic array of TPads

Hi I would like to make a dynamically sized array of TPad Objects and
nothing I try seems to work. I have tried:

TPad * p = new TPad[size];

and

std::vector<TPad> p;
p.resize(size);

Could someone offer me some helpful advice. Thanks.


Loren A. Linden Levy
481 Loomis, Department of Physics
University of Illinois at Urbana-Champaign
1110 W. Green St., Urbana, IL 61801-3080
Tel: 217-244-7995 (NPL) / +049 040 8998 4789 (DESY)
Fax: 217-333-1215 (NPL) / +049 040 8998 4034 (DESY)
Cell: 217-369-6580 (U.S.) / +049 (0)151 5496 1831 (Germany)
Email: lindenle@uiuc.edu
url: w3.physics.uiuc.edu/~lindenle/



This email has been cryptographically signed.
Search for “lindenle” at pgp.mit.edu
to obtain my public key which can be used
to verify the authenticity of this message.



[quote=“lindenle”] I have tried:

TPad * p = new TPad[size];

and

std::vector<TPad> p;
p.resize(size);

[/quote]

Both of these should work if you are compiling your code. I have used STL vectors in CINT with (a surprising amount of) success (I’ve never tried new. What do you mean by doesn’t work?

Cheers,
  Charles

[quote]Hi I would like to make a dynamically sized array of TPad Objects and
nothing I try seems to work. I have tried:

std::vector<TPad> p;
p.resize(size);

Could someone offer me some helpful advice. Thanks.
[/quote]

std::vector requires it’s value_type to be copy-constructible and copy-assignable. TPad is not - it has private copy-asisgnment operator and copy-constructor (AFAIK they are even not implemented, only declared).

And this is not bad, vector (during it’s modifying operations) can reallocate memory and copy objects into this new place, it will be really bad to copy big array of TPad’s, they are havy-weight objects.
You can use array of pointers to TPads (or vector of such pointers), but the best (IMHO) for you situation solution is to use ROOT’s specific container for TObject’s inherited objects - TObjArray (somthing like this, I didn’t check this code):

TObjArray arr;
//I think, you can even do arr.SetOwner(kTRUE); not to delete TPads
//yourself, TObjArray must do it for you.
arr.AddLast(new TPad(someParameters));
//etc.

Or, may be, you can use TClonesArray.

You cannot use std::vector with TPad, even if you compiler managed to compile this - such code is ill-formed in C++ terms.
C++ standard requires vector’s value type to be copy-constructible and copy-assignable, TPad (at least in CVS head) is not.