Problems with templates and typedefs in CINT dictionary

Hi All

I am trying to generate the cint dictionary for
template classes using typedefs as template argument.

  • I have a template class QBaseType that inherits from
    TObject:
 template<class T> class QBaseType : public TObject {
      public:
        QBaseType() {};
        virtual ~QBaseType() {};

      private:
        T fValue;
        ClassDef(QBaseType,1);

  };

This class is intended to be used with base types,
so I defined the following typedefs

typedef QBaseType<int> QInt;
typedef QBaseType<float> QFloat;
  • I have another template class QHandle, that should be able to
    have a QBaseType as template argument:
  template<class Q> class QHandle {
      public:
          QHandle(const std::string& name) { fName=name; }
          virtual ~QHandle() {};
      private:
          std::string fName;
          Q fObject;

  };

everithing is defined inside a namespace named “Cuore”.

My LinkDef.h looks like:

#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ namespace Cuore;

#pragma link C++ class Cuore::QBaseType    <int>+;
#pragma link C++ typedef Cuore::QInt;
#pragma link C++ class Cuore::QBaseType    <float>+;
#pragma link C++ typedef Cuore::QFloat;

#pragma link C++ class Cuore::QHandle<Cuore::QBaseType<int> >;
#pragma link C++ class Cuore::QHandle<Cuore::QInt>;
#pragma link C++ class Cuore::QHandle<Cuore::QBaseType<float> >;
#pragma link C++ class Cuore::QHandle<Cuore::QFloat>;
#endif

In the cint shell I am able to run the following commands:

root[] Cuore::QBaseType<int> b;
root[] Cuore::QInt a;
root[] Cuore::QHandle<Cuore::QBaseType<int> > h("dummy");

but the following command fails

root[] Cuore::QHandle<Cuore::QInt> g("dummy");

with error:

Error: Function QInt>g("dummy") is not defined in $QHandle<Cuore  macro.C:13:

I am using root version:
ROOT 5.26/00 (trunk@31882, Dec 14 2009, 20:18:36 on linux)
I prepared a minimal code and a macro to reproduce the problem
which is attached to this message (templatetypedef.tgz).
The code can be compiled with the command “source compile.sh”
and the macro can be run as “root -l macro.C”

I have tried many different things in the source files and in the LinkDef.h
file but I have not been able to fix the problem.
Thanks a lot in advance for any help,

marco
templatetypedef.tgz (1 KB)

run your stuff with ACLIC, ie instead of

root -l macro.C do

root -l macro.C+
Rene

Hi Rene,

thanks for your answer. The macro runs well if compiled with aclic.
Does this mean that the CINT interpreter is not able to understand
typedefs as template arguments?
Am I missing something in the LinkDef.h?

thank you,

Marco

As soon as you use a mixture of templated code and typedefs you should use ACLIC (it is so simple).
it is difficult to come with a rule where to use CINT or not with templates. You must have a dictionary anyhow
and ACLIC is doing that in a transparent way for you.

Rene