RE: [ROOT] namespace problem

From: thorsten glebe (glebe@mpi-hd.mpg.de)
Date: Wed Nov 22 2000 - 12:10:50 MET


Dear Philippe,

> There is no quick fix beside not using namespace or applying the patch below.
>
> Philippe.
>
> diff -r1.1.1.1 TBaseClass.cxx
> 83c83
> <    return fInfo->Name();
> ---
> >    return fInfo->Fullname();
>

thanks for the answer. The patch improved the situation, but unfortunately
didn't solve the problem.

Before the patch, the InheritsFrom() method failed always.
After the patch the following happens:

root [0] using namespace TG
root [1] MyLeaf a
 MyClass constructor
 MyLeaf constructor
root [2] a.InheritsFrom(TObject::Class())
(const unsigned char)0
root [3] a.InheritsFrom(MyClass::Class())
(const unsigned char)1
root [4] a.InheritsFrom(TObject::Class())
(const unsigned char)1

The weired statement is [2]. The InheritsFrom() method fails
the first time, later it works.

What else has to be patched?

Goodbye,
  Thorsten

----------------------------------------------------
Dr. Thorsten Glebe    <Thorsten.Glebe@mpi-hd.mpg.de>

        Max-Planck-Institut fuer Kernphysik

Saupfercheckweg 1                 Tel: 06221/516-631
D-69117 Heidelberg                Fax: 06221/516-603
----------------------------------------------------

On Tue, 21 Nov 2000, Philippe Canal wrote:

> Hi,
>
> There is a very small bug that prevents the TClonesArray to properly detect the
> name of the base class (if the base class is inside a namespace or another class).
>
> > -----Original Message-----
> > From: owner-roottalk@pcroot.cern.ch
> > [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of thorsten glebe
> > Sent: Tuesday, November 21, 2000 9:57 AM
> > To: roottalk@pcroot.cern.ch
> > Subject: [ROOT] namespace problem
> >
> >
> > Hello,
> >
> > I have a problem using namespace. If I define two classes
> > (MyClass, MyLeaf) inside a namespace (e.g. namespace TG),
> > with MyLeaf inherited from MyClass, and MyClass inherited from TObject,
> > then root forgets that MyLeaf is inherited from TObject, too.
> >
> > MyLeaf looks fine with the .class command, but using
> > the ClassDraw() command, MyLeaf looks like a base class.
> > Even worse, when trying to save a MyLeaf Object-Pointer
> > in a TClonesArray I get the following error:
> >
> > Error in <TClonesArray::TClonesArray>: TG::MyLeaf does not inherit
> > from TObject
> >
> > I am using root version 2.25.03.
> >
> > Is there a solution to this problem?
> >
> > Goodbye,
> >   Thorsten
> >
> >
> > Code: (MyClass.hh)
> >
> > #include <TObject.h>
> >
> > namespace TG {
> >
> >   class MyClass : public std::TObject {
> >   public:
> >     MyClass();
> >
> >     int Loop();
> >
> >     ClassDef(MyClass,1)
> >   };
> >
> >
> >   class MyLeaf : public MyClass {
> >   public:
> >     MyLeaf();
> >     int print();
> >
> >     ClassDef(MyLeaf,1)
> >   };
> > } // end of namespace
> >
> >
> > MyClass.C:
> >
> > #include <iostream>
> > #include "MyClass.hh"
> >
> > namespace TG {
> >
> >   MyClass::MyClass() {
> >     std::cout << " MyClass constructor" << endl;
> >   }
> >
> >   int MyClass::Loop() {
> >     cout << " Myclass loop " << endl;
> >     return 0;
> >   }
> >
> >   ClassImp(MyClass)
> >
> >   MyLeaf::MyLeaf() {
> >     std::cout << " MyLeaf constructor" << endl;
> >   }
> >
> >   int MyLeaf::print() {
> >     cout << " MyLeaf loop " << endl;
> >     return 0;
> >   }
> >
> >   ClassImp(MyLeaf)
> >
> > }
> >
> >
> > LinkDef.h:
> >
> > #ifdef __CINT__
> >
> > #pragma link off all globals;
> > #pragma link off all classes;
> > #pragma link off all functions;
> >
> > #pragma link C++ nestedclasses;
> > #pragma link C++ nestedtypedefs;
> >
> > #pragma link C++ namespace TG;
> > #pragma link C++ class TG::MyClass;
> > #pragma link C++ class TG::MyLeaf;
> > #endif
> >
> >
> > ----------------------------------------------------
> > Dr. Thorsten Glebe    <Thorsten.Glebe@mpi-hd.mpg.de>
> >
> >         Max-Planck-Institut fuer Kernphysik
> >
> > Saupfercheckweg 1                 Tel: 06221/516-631
> > D-69117 Heidelberg                Fax: 06221/516-603
> > ----------------------------------------------------
> >
> >
> >
>
>



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:37 MET