Re: [ROOT] multiple inheritance from TObject

From: Stephen J. Gowdy (gowdy@SLAC.stanford.edu)
Date: Mon Apr 28 2003 - 18:39:16 MEST


You need to use virtual inheritance (so that there is only one versin of 
the common base class) probably, this is C++ though, not ROOT.

On Mon, 28 Apr 2003, Benoit Revenu wrote:

> Dear Rooters,
> 
> I want a class to inherit from 2 others classes inheriting from TObject.
> I don't need this class to be in a dictionnary so that I DON'T get the 
> rootcint error message :
> -------------------------
> Warning: multiple ambiguous inheritance TObject and C. Cint will not get 
> correct base object address
> 
> I would like to do something like :
> --------------------------------------------
> cat test.h:
> --------------------------------------------
> #include "TMinuit.h"
> #include "TObject.h"
> 
> class A : public TMinuit
> {
>   public:
>   A(){}
>   ~A(){}
>   int a;
>   ClassDef(A,1)
> };
> 
> class B : public TObject
> {
>   public:
>   B(){}
>   ~B(){}
>   int b;
>   ClassDef(B,1)
> };
> 
> class C : public A, public B
> {
>   public:
>   C(){}
>   //~C(){}
>   int c;
> };
> 
> -------------------------------------------------
> cat test.cc:
> -------------------------------------------------
> #include "test.h"
> 
> ClassImp(A)
> ClassImp(B)
> -------------------------------------------------
> 
> -------------------------------------------------
> cat LinkDef.h:
> -------------------------------------------------
> #ifdef __CINT__
> 
> #pragma link off all globals;
> #pragma link off all classes;
> #pragma link off all functions;
> #pragma link off all typedef;
> 
> #pragma link C++ class A;
> #pragma link C++ class B;
> 
> #endif
> 
> 
> Everything is ok if the destructor of C is commented out. If I remove the 
> destructor, I got :
> ../src/test.h: In method `C::~C ()':
> ../src/test.h:26: request for member `operator delete' is ambiguous
> /opt/root/include/TObject.h:164: candidates are: static void 
> TObject::operator delete (void *, void *)
> /opt/root/include/TObject.h:162: candidates are: static void 
> TObject::operator delete (void *)
> /opt/root/include/TObject.h:164:                 static void 
> TObject::operator delete (void *, void *)
> /opt/root/include/TObject.h:162:                 static void 
> TObject::operator delete (void *)
> 
> What can I do ? Is it even possible ?
> 
> 
> 

-- 
 /------------------------------------+-------------------------\
|Stephen J. Gowdy                     | SLAC, MailStop 34,       |
|http://www.slac.stanford.edu/~gowdy/ | 2575 Sand Hill Road,     |
|http://calendar.yahoo.com/gowdy      | Menlo Park CA 94025, USA |
|EMail: gowdy@slac.stanford.edu       | Tel: +1 650 926 3144     |
 \------------------------------------+-------------------------/



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET