[ROOT] templates and namespace

From: thorsten glebe (glebe@mpi-hd.mpg.de)
Date: Wed Nov 22 2000 - 09:52:58 MET


Hello,

assuming you have a template class and some classes inside a namespace
making use of the template like in the following example:

headerfile.hh:

template <class T> class GobalPtr { ... }

namespace TG {

  class A {
	...
    ClassDef(A,1)
  }

  class B {
    ...
    GobalPtr<A> x;

    ClassDef(B,1)
  }
}


The above construct is fine for a usual compiler, and also rootcint will
process this, but compilation of the dictionary will fail, because
the template argument cannot be recognized.

To avoid this, one has specify the full name of type A:

  class B {
  ...
  GobalPtr<TG::A> x;
  ...
  }

It is tedious to always specify the full class name in template arguments
and it doesn't allow to easily enable/disable the namespace (e.g. by
a preprocessor flag).

But there is a simple and obvious trick to avoid the scope problem in
the  dictionary. One simply has to smuggle a "using namespace"
statement into the dictionary file, e.g. via a header file which is
processed by rootcint:

namespace.hh:

#ifndef __CINT__
using namespace TG;
#endif

Wouldn't it be nice if rootcint could place such "using namespace"
commands automatically in the dictionary file when it encounters a
namespace? Then the scope problems in the dictionary are reduced to
real scope clashes.

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
----------------------------------------------------



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