Data member TClonesArray in TObject inheritance

William J. Deninger (deninger@uiuc.edu)
Wed, 31 Dec 1997 15:40:13 -0600


Hello,

I've discovered that I'm unable to compile a class with a TClonesArray data
member using MCVC v5.0 compiler without an error. Is it not syntactically
correct to have a data member use a specialized constructor within the class
declaration?

// code..
#include "TObject.h"
#include "MPXPAIR.h" // class MPXPAIR inherits TObject
#include "TClonesArray.h"
class Simple : public TObject
{
public:
Simple();
virtual ~Simple();
TClonesArray tracks("MPXPAIR", 10);
ClassDef(Simple,1)
};

// compile message
Compiling...
Simple.cpp
D:\Root-Trace\Simple.h(18) : error C2059: syntax error : 'string'
Error executing cl.exe.
Simple.obj - 1 error(s), 0 warning(s)

Of course, if I have the a variable of type TClonesArray instantiated from
within a member function, things compile perfectly but I loose the "public"
accessibility of the variable. To get around the error I can make the
declared data member a pointer of type TClonesArray and having the memory
allocated and constructor called from with the Simple class constructor.
But this seems to have repercussions on my ability to use Simple in a TTree
with splitlevel = 1. My whole reason for using TClonesArray was to get away
from pointers.

How should I be approaching this? And much thanks for all your help.

William Deninger
deninger@uiuc.edu