CINT can't find static template functions

Good afternoon.
I use ROOT 5.34.34 version and encountered with the error concerned with calling static template function (in a class) from the Root interpreter.

[code]#include “TString.h”

class UniDbTemplate
UniDbTemplate(); // Constructor
virtual ~UniDbTemplate(); // Destructor

static void template_example(T a)

template void UniDbTemplate::template_example(int);

#include “UniDbTemplate.h”


When I try to call static template function it leads to the error. e.g. root [1] UniDbTemplate::template_example(1);
[i]Error: cannot call member function without object (tmpfile):1:
/home/soul/build/lib/ -1 void UniDbTemplate::template_example(int);
Calling : UniDbTemplate::template_example(int);
Match rank: file line signature

  •    1 /home/soul/build/lib/  -1 void UniDbTemplate::template_example(int);

*** Interpreter error recovered ***[/i]

Why can’t CINT find template functions defined as static in a class?

I cannot reproduce:

pb-d-128-141-192-64:build.v5-34-00-patches mato$ root.exe
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   5.34/35    2 October 2015   *
  *                                         *
  *  You are welcome to visit our Web site  *
  *            *
  *                                         *

ROOT 5.34/35 (v5-34-34@v5-34-34, Oct 02 2015, 16:30:37 on macosx64)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .x UniDbTemplate.cxx
(const class UniDbTemplate)140198659007904
root [1] UniDbTemplate::template_example(1);
root [2] .q

OK. I see we where loading a compiled library. In this case you need to hint CINT to create the necessary entries in the dictionary for the template function instances.

// In UniDbTemplate.h
#ifdef __CINT__
  #pragma link C++ function UniDbTemplate::template_example(int);
  #pragma link C++ function UniDbTemplate::template_example(char*);
  template void UniDbTemplate::template_example(int);
  template void UniDbTemplate::template_example(char*);
root [0] 
Processing UniDbTemplate.cxx+...
Info in <TMacOSXSystem::ACLiC>: creating shared library /Users/mato/Development/ROOT/build.v5-34-00-patches/./
(class UniDbTemplate)140554436792496
root [1] UniDbTemplate::template_example(1);
root [2] UniDbTemplate::template_example("abc");

Sorry, I haven’t mentioned that I use this class being part of the ‘libUniDb’ library by loading of the library in CINT:

root [0] gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C"); root [1] basiclibs(); root [2] gSystem->Load("libUniDb"); root [3] UniDbTemplate::template_example(1);

I have added to UniDbTemplate.h:

#ifdef __CINT__ #pragma link C++ function UniDbTemplate::template_example(int); #else template void UniDbTemplate::template_example(int); #endif
instead of:

And now it’s working!
Just some kind of magic. Because I had tried to add the following line to UniDbLinkDef.h:
#pragma link C++ function UniDbTemplate::template_example(int);
but it didn’t solve my problem and the function ‘template_example’ was remaining non-static function (as without any hint - CINT could find the function but only as non-static). I don’t understand what’s the difference between your correct proposition and my correction of UniDbLinkDef.h.

Thank you much.

The only explanation I have is that CINT does not like explicit function template instantiations like:

template void UniDbTemplate::template_example(int);

So, ifdefing it with CINT make them invisible to CINT.