Re: [ROOT] Clarification needed

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Oct 18 2001 - 18:35:17 MEST


Hi Laurent,

You must have a ClassDef(A,1) in your class A
              a ClassDef(B,1) in your class B
and your LinkDef.h file include be:

#pragma link C++ class A+;
#pragma link C++ class B+;

Rene Brun

Laurent Aphecetche wrote:
> 
> Hi,
> 
> A very generic (and very naive probably) question about ClassDef and
> ClassImp. All my apologies if this is really trivial.
> 
> Assume I have a class A deriving from TObject :
> 
> class A : public TObject {
> public:
>   virtual void SomeMethod(void) = 0 ;
> } ;
> 
> and a class B deriving from A :
> 
> class B : public A
> {
> public:
>   B() : A() { }
>   virtual ~B() { }
> 
>   virtual void SomeMethod(void) { cout << "fSize" << endl ; }
> 
> private:
>   Int_t fSize ;
> 
>   ClassDef(B,1)
> } ;
> 
> Class A is meant to be just an interface (and to provide a
> "TObject"-type), no I/O intended, but I'd like the following to work
> under the ROOT prompt :
> 
> root[0] A* a = new B() ;
> root[1] a.SomeMethod() ;
> 
> i.e. my class A must be in the dictionnary.
> 
> Class B is meant to be a persistent object, so I put a ClassDef/ClassImp
> in there.
> 
> So here are the questions then :
> 
> a) should I put a ClassDef(A,i) (i=0 ?) in class A ?
> 
> b) what should be the corresponding LinkDef.h file for those two classes
> in order to i) have access to the A methods from the root prompt and ii)
> being able to write B objects into a ROOT file.
> 
> I made some tests and would conclude that I must put a ClassDef(A,0) and
> use
> 
> #pragma link C++ class A;
> #pragma link C++ class B; // or B+;
> 
> if I want my stuff to work.
> 
> BTW, in real life, class A is not one I get much control on ; it does
> not have a ClassDef, and uses
> 
> #pragma link C++ class A-! ;
> 
> Is that wrong or not ?
> 
> Thanks for your help,
> 
> Best regards,
> 
> PS: I'm using ROOT 3.01/05 on a Linux box.
> --
> Dr. Laurent APHECETCHE (mailto:aphecetc@in2p3.fr) (IN2P3-CNRS)
> SUBATECH-EMN-4 rue Alfred Kastler-BP 20722-44307 NANTES cedex 03
> TEL (+33/0) 2 51 85 84 17 - FAX (+33/0) 2 51 85 84 24 (France)
> Collaborations PHENIX http://www.phenix.bnl.gov/~aphecetc et MEGAPIE.



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