TDirectory inheritance

William J Deninger (deninger@uiuc.edu)
Thu, 2 Apr 1998 16:30:40 -0600


This is a multi-part message in MIME format.

------=_NextPart_000_000B_01BD5E54.AC7EB210
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,

Is is possible to have a class (say X) inherit TDirectory and still be =
accessible as its class type (X) with TDirectory functionality when =
written to a TFile? I'm finding that once I close and reopen the file, =
the Class X object is gone and only the TDirectory portion remains. How =
should I approach this problem?

// example
//___________________
class X : public TDirectory
{
public:
X() : TDirectory();
X(Text_t *name, Text_t *title) : TDirectory(name, title);
virtual ~X();

void Hi();
ClassDef(X,1);
} =20

//____________________
void X::Hi() { printf("hello to you too\n"); }
//___________________

the current keyboard layout is 437
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 1.03/09 16 December 1997 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************

CINT/ROOT C/C++ Interpreter version 5.13.36, Nov 30 1997
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] f =3D new TFile("e:/data/g2trace;3.root","recreate");
root[1] X *x =3D new X("myx","my X class");
root[2] f.ls()
TFile** e:/data/g2trace;3.root
TFile* e:/data/g2trace;3.root
X* myx my X class
KEY: TDirectory myx;1 myx
root[3] x.Write();
root[4] f.Write();
TFile Writing Name=3De:/data/g2trace;3.root Title=3D
root[5] .q

//__________________________________
the current keyboard layout is 437
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 1.03/09 16 December 1997 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
=20
CINT/ROOT C/C++ Interpreter version 5.13.36, Nov 30 1997
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] f =3D new TFile("e:/data/g2trace;3.root","update");
root[1] f.ls();
TFile** e:/data/g2trace;3.root
TFile* e:/data/g2trace;3.root
KEY: TDirectory myx;1 myx
root[2] myx.Hi();
Error: No symbol myx.Hi() in current scope FILE:D:\TEMP\466 LINE:1
*** Interpreter error recovered ***

William J Deninger
deninger@uiuc.edu

------=_NextPart_000_000B_01BD5E54.AC7EB210
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">

Hello,
 
Is is possible to have a class (say X) inherit = TDirectory and=20 still be accessible as its class type (X) with TDirectory functionality = when=20 written to a TFile?  I'm finding that once I close and reopen the = file, the=20 Class X object is gone and only the TDirectory portion remains.  = How should=20 I approach this problem?
 
// example
//___________________
class X : public TDirectory
{
public:
    X() :=20 TDirectory();
    X(Text_t *name, = Text_t=20 *title) : TDirectory(name, title);
    virtual=20 ~X();
 
    void = Hi();
    = ClassDef(X,1);
 
//____________________
void X::Hi() { printf("hello to you = too\n");=20 }
 //___________________
 
 the current keyboard layout is 437
 =20 *******************************************
 =20 *            =             &= nbsp;           &n= bsp;   =20 *
  *        W E L C O M = E =20 to  R O O T       *
 =20 *            =             &= nbsp;           &n= bsp;   =20 *
  *   Version   1.03/09  16 December=20 1997   *
 =20 *            =             &= nbsp;           &n= bsp;   =20 *
  *  You are welcome to visit our Web site  = *
 =20 *          http://root.cern.ch   &nb= sp;       =20 *
 =20 *            =             &= nbsp;           &n= bsp;   =20 *
  *******************************************
 
CINT/ROOT C/C++ Interpreter version 5.13.36, Nov 30=20 1997
Type ? for help. Commands must be C++ statements.
Enclose = multiple=20 statements between { }.
root [0] f =3D new=20 TFile("e:/data/g2trace;3.root","recreate");
root[1] X *x =3D new X("myx","my X=20 class");
root[2] f.ls()
TFile**        =20 e:/data/g2trace;3.root
 TFile*      = ;  =20 e:/data/g2trace;3.root
 =20 X*          =20 myx        my X class
  KEY: = TDirectory      =20 myx;1    myx
root[3] x.Write();
root[4] f.Write();
TFile Writing Name=3De:/data/g2trace;3.root = Title=3D
root[5] .q
 
//____________________= ______________
the current keyboard layout is 437
 =20 *******************************************
 =20 *            =             &= nbsp;           &n= bsp;   =20 *
  *        W E L C O M = E =20 to  R O O T       *
 =20 *            =             &= nbsp;           &n= bsp;   =20 *
  *   Version   1.03/09  16 December=20 1997   *
 =20 *            =             &= nbsp;           &n= bsp;   =20 *
  *  You are welcome to visit our Web site  = *
 =20 *          http://root.cern.ch   &nb= sp;       =20 *
 =20 *            =             &= nbsp;           &n= bsp;   =20 *
  *******************************************
 
CINT/ROOT C/C++ Interpreter version 5.13.36, Nov 30=20 1997
Type ? for help. Commands must be C++ statements.
Enclose = multiple=20 statements between { }.
root [0] f =3D new=20 TFile("e:/data/g2trace;3.root","update");
root[1] f.ls();
TFile**        =20 e:/data/g2trace;3.root
 TFile*      = ;  =20 e:/data/g2trace;3.root
  KEY:=20 TDirectory       myx;1   =20 myx
root[2] myx.Hi();
Error: No symbol myx.Hi() in current = scope =20 FILE:D:\TEMP\466 LINE:1
*** Interpreter error recovered ***
 
 
William J Deninger
deninger@uiuc.edu
------=_NextPart_000_000B_01BD5E54.AC7EB210--