Rene, thanks for the help, for anyone else with this problem I finally found out that this works too (hope that this is not wrong and just works by accident): pBase=(TJObject*)(TMyDerivedClass*)File.Get("MyDerivedClass); Joe > > JoeDerived *MyDerivedClass = new JoeDerived; > TJObject* pBase = (TJObject*)&MyDerivedClass; > > is perfectly legal. > > BUT, not the following operation > pBase=(TJObject*)File.Get("MyDerivedClass"); > > File.Get returns a TObject*. You cannot cast it to TJObject* > One has to do: > > pBase=(MyDerivedClass*)((void*)File.Get("MyDerivedClass")); > > see: http://root.cern.ch/root/htmldoc/TDirectory.html#TDirectory:Get > > Rene > > joer00@bellsouth.net wrote: > > > > Rene and others, > > > > well I STILL go mad with this problem. Your example works but my setup does NOT. > > > > The virtual function call fails when I use the GET method !!! > > > > class TJObject > > { > > TJObject(){}; > > virtual function Visualize(){printf("class TJObject called\n");}; > > } > > > > class JoeDerived:public TVectorD,public TJObject > > { > > JoeDerived(){}; > > virtual function Visualize(){printf("class JoeDerivedcalled\n");}; > > } > > > > Now in main: > > > > TJObject* pBase; > > JoeDerived MyDerivedClass; > > TFile File("f:\\Shittemp\\rotz.root","RECREATE"); > > MyDerivedClass.Write("MyDerivedClass"); > > pBase=(TJObject*)&MyDerivedClass; > > pBase->Visualize(); -->WORKS CORRECT > > pBase=(MyDerivedClass*)File.Get("MyDerivedClass"); > > pBase->Visualize(); -->WORKS CORRECT > > pBase=(TJObject*)File.Get("MyDerivedClass"); > > pBase->Visualize(); -->Does NOT WORK !!! (sometimes just prints nothing, sometimes crashes) > > > > Now I tried to do: > > > > class TJObject:public TObject > > { etc. > > > > But now I get tons of ambitious errors in TJoeDerived ... > > > > So I am still happy for any help how to create this correct ! > > > > Joe > > > > > > > > From: Rene Brun <Rene.Brun@cern.ch> > > > Date: Wed, 23 Jan 2002 17:05:44 +0000 > > > To: joer00@bellsouth.net > > > CC: roottalk@pcroot.cern.ch > > > Subject: Re: [ROOT] Multiple inheritance from TObject problem/ old cutoms class read/write problem > > > > > > 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:40 MET