Re: VC/CC C++ and multiple inheritance

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Tue Nov 30 1999 - 16:19:57 MET


Hi Anton,

   in this case you've created the so called "diamond" inheritance tree (TObject
gets
included twice in your TTimeSeries object). If you really want to do this you
should use virtual inheritance, but that opens an even bigger can of worms.
Best is to see if you could change the inheritance tree, e.g. a TTimeSeries
could inherit from TGraph and contain a TObjArray, or vice versa, just what is
more convenient (for one of the contained classes you will probably have to
provide some "relay" methods, like: TTimeSeries::Add(xxx) { fArray->Add(); }
which would not be necessary in case of inheritance).

Cheers, Fons.


Anton Fokin wrote:
> 
> Hi rooters,
> 
> here is a C++ question. I made a class TTimeSeries, which is derived from TObjArray and TGraph. I can compile the class on Sun Solaris with CC but if I move to VC6, it says:
> 
> loader.cxx(283) : error C2385: 'TTimeSeries::new' is ambiguous
> loader.cxx(283) : warning C4385: could be the 'new' in base 'TObject' of base 'TCollection' of base 'TSeqCollection' of base 'TObjArray' of class 'TTimeSeries'
> loader.cxx(283) : warning C4385: or the 'new' in base 'TObject' of base 'TNamed' of base 'TGraph' of class 'TTimeSeries'
> loader.cxx(283) : error C2385: 'TTimeSeries::delete' is ambiguous
> loader.cxx(283) : warning C4385: could be the 'delete' in base 'TObject' of base 'TCollection' of base 'TSeqCollection' of base 'TObjArray' of class 'TTimeSeries'
> loader.cxx(283) : warning C4385: or the 'delete' in base 'TObject' of base 'TNamed' of base 'TGraph' of class 'TTimeSeries'
> 
> Well, that's fine, but remaining questions are
> 
> 1) what is a correct way to solve this problem and is this a problem?
> 2) if I can compile this under CC ... will I get any "bad" things around new and delete during run time?
> 3) both base-base classes for TTimeSeries are the same, i.e. TObject. Why VC thinks it is ambiguous definition?
> 
> Best regards,
> Anton

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:43 MET