Re: [ROOT] class data member TList

From: Victor Perevoztchikov (perev@bnl.gov)
Date: Fri Jun 01 2001 - 05:27:12 MEST


Hi Stephen,
> It seems confused about what the default constructor for TList
it confused about copy constructor of TList.
Copy constructor of TList intentially has made private.
It is ambiguity there: 
- you want copy only pointers, then method TList::Delete becomes dangerous
- you want copy objects also.
To avoid it you should define copy ctr of your class, and copy TList as you want.
If you do not need your copy CTR at all, define it private.
Then C++ will not create automatacally your copy ctr, and you avoid
your problem with TList member.

> If I use a TObjArray instead of a TList, it works
Actually the same problem with TObjArray. It also should have
private copy ctr, ROOT team just forgot to do it.
Victor


Stephen Bailey wrote:
> 
> Hello.
> 
> The following class works fine when loaded interactively
> with .L Blat.cc.  When I try to make it into a compiled ROOT
> object by making it inherit from TObject, etc. (see attached
> files) and then compile it with .L Blat.cc+, I get the errors:
> 
> TCollection.h: In method `TSeqCollection::TSeqCollection(const
> class TSeqCollection &)': TCollection.h:53:
> `TCollection::TCollection(const class TCollection &)' is private
> within this context
> 
> It seems confused about what the default constructor for TList
> should be.  If I use a TObjArray instead of a TList, it works
> fine for the compiled version.  It also works fine if I use a
> pointer to a TList or a TObjArray.  But it seems to choke when
> my class has a TList as a data member.
> 
> I'm using Root 3.01/02 on Linux.  The test class is:
> 
> class Blat {
> 
> public:
>   Blat() {}
> 
>   void Print(void);
>   void Add(TObject *x);
> 
> private:
>   TList _list;
>   //  TObjArray _list;
> 
> };
> 
> void Blat::Print(void) { cout << _list.GetSize() << endl; }
> 
> void Blat::Add(TObject *x) { _list.Add(x); }
> 
> Any ideas/comments/assistance?  Thanks.
> 
> Stephen
> 
>   ------------------------------------------------------------------------------------------------------------------------------------
>               Name: Blat.hh
>    Blat.hh    Type: Plain Text (TEXT/PLAIN)
>           Encoding: 7BIT
> 
>               Name: Blat.cc
>    Blat.cc    Type: Plain Text (TEXT/PLAIN)
>           Encoding: 7BIT

-- 
Victor M. Perevoztchikov   perev@bnl.gov  perev@vxcern.cern.ch       
Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000
tel office : 631-344-7894; fax 631-344-4206; home 631-345-2690



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:47 MET