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.
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/libUniDb.so -1 void UniDbTemplate::template_example(int);
Calling : UniDbTemplate::template_example(int);
Match rank: file line signature
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 *
* http://root.cern.ch *
* *
*******************************************
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);
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*);
#else
template void UniDbTemplate::template_example(int);
template void UniDbTemplate::template_example(char*);
#endif
#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.