Confused about Object I/O and needed pragmas

Hi,

I am been testing the Object I/O functionality by loading a class from a script (using the ABC Class example taken from chapter 7 on “Adding a Class”, page 281-282, end of that chapter), as given below:

#include “TObject.h”
// define the ABC class and make it inherit from TObject so that we can write
// ABC to a ROOT file
class ABC : public TObject {
public:
Float_t a, b, c, p;
ABC() : a(0), b(0), c(0), p(0){};

// Define the class for the cint dictionary
ClassDef (ABC,1)
};
// Call the ClassImp macro to give the ABC class RTTI and full I/O capabilities.
#if !defined(CINT)
ClassImp(ABC);
#endif

I am using ROOT version 5.22 on a Linux box

Here are my specific questions:

Q1: Chapter 7 “Cint the C++ Interpreter”, bottom of page 90, says a Class defined in a cript can not inherit from TObject. Yet, the ABC class given above inherits from the TObject and can still be loaded using a script (.L ABCClass.C) and object I/O functionality seems to be full on. I was able to write and read an ABC object to and from a ROOT file in interpreted mode. Is this portion of the documentation in Chapter 7 outdated now, since TObject can now be inherited in script in interpreted mode?

Q2: I then deleted the ClassImp(ABC) macro, I did not provide “#pragma link c++ ABCClass” in the ABCClass.C script or in a link_def.h file, and yet, the ABCClass.C could still be compiled by ACLiC (.L ABCClass.C+).
Does it mean that the “#pragma link c++ ABCClass” and “ClassImp(ABC)” macro are not needed by ACLiC, and are only needed if I use rootcint to create a dictionary before compiling?

Thanks in advance.

Vi-Hoa

Hi,

ClassImp is only needed for documenting classes with THtml, so it can find the source file for a class.

The warning about inheritance is generally correct; ROOT cannot determine the derived class’s type given a pointer to the base class if the derived class is an interpreted class, it also cannot call virtual functions that are re-implemented in the derived (interpreted) class, because it does not manipulate the compiled class’s vtable for the derived, interpreted class.

For ACLiC (i.e. .L X.C+) you don’t need to provide a linkdef file, it is automatically generated by ACLiC. You need the linkdef file only if you run rootcint by hand.

Summary: you found two spots in the users guide that we have to fix!

Cheers, Axel.