RE:rootcint and templates

Masaharu Goto (MXJ02154@nifty.ne.jp)
Mon, 24 Aug 1998 23:09:00 +0900


Christoph,

>The STLObjArray, which I am currently writing, is supposed to store only
>pointers to objects derived from TObject. My first problem is, that
>rootcint cannot parse pointer templates. It simply skips the second
>line of these:
>
>#pragme link C++ class MC_Track;
>#pragma link C++ class STLObjArray<MC_Track*>-;
>
>If I remove the `*', it gives at least a warning or an error about this
>line (since I need only pointers, I did not investigate the errors
>precisely). Would there be the possibility to extend rootcint?

I have a few comments to this.

First, #pragma link command does not instatiate the template class, it only
tries to refer already instantiated template classes. In order to link
instantiated template class, you need to instantiate it in normal C++ code.
For example,

typedef STLObjArray<MC_Track*> DummyType1;
#pragma link C++ class STLObjArray<MC_Track*>-;

But, I understand it is nice to instantiate template class on #pragma link.
I'll think about doing this in future version.

Second, #pragma link command with '*' in it's name field behaves somewhat
differently. Rootcint or cint takes it as a wildcard character. So, it is
actually interpreted as 'STLObjArray<MC_Track[A-Za-z0-9_]*'. This is usually
fine, except that '-' flag at the end is ignored. For now, workaround is to
use typedef.

typedef MC_Track* pMC_Track;
typedef STLObjARray<pMC_Track> DummyType1;
#pragma link C++ class STLObjArray<pMC_Track>-;

I want to improve this in future version.

Masaharu Goto