Re: [ROOT] Multiple inheritance from TObject problem/ old cutoms class read/write problem

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Jan 23 2002 - 18:05:44 MET


I think that giving a simple example is better:

//-------file joe.cxx
#include "TObject.h"
   
//-------------------------
class A {

private:
   int fA1;
   int fA2;

public:
   A() {fA1=1;fA2=2;}
   ClassDef(A,0)
};

//-------------------------
//class B : public A, public TObject {   //<===wrong order
class B : public TObject, public A {
   
private:
   int fB1;
   int fB2;
   
public:
   B() {fB1=11;fB2=12;}

ClassDef(B,1)
};

ClassImp(A)
ClassImp(B)
//------------end of jeoe.cxx

In interactive root, do
root > .L joe.cxx++
root > TFile f("junk.root","recreate");
root > B b;
root > b.Write("b");

ClassDef is mandatory for all classes involved in I/O.
Specify ClassDef(A,0) if you do not want to write the members

Rene Brun


joer00@bellsouth.net wrote:
> 
> Rene,
> 
> just to be 100 % sure now, from you posts this should work: (if yes just asnwer yes to save time, if no please explain because it than cotradicts with your provious posts !)
> 
> Class A does NOT deriver from TObject, does NOT define the ClassDef macros and has NO streamer. It HAS datamemebers which I do NOT want/need to write to disk.
> 
> Class B:public A,TObject
> 
> DOES deriver from TObject, DOES implement ClassDef, HAS a dictionary file,HAS data members which need to be written to disk.
> 
> BObject->Write("NAME"); and
> BObject=(B*)SomeFile->Get("Name");
> 
>  WILL work although base class does NOT deriver from TObject and has no streamer !
> 
> Joe



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:39 MET