Hi ROOTers,
I’m having trouble with a probably-trivial LinkDef file. I think that if you could help me with the following simplified class, I could take it from there.
The class is declared and defined in MyClass.h:
// MyClass.h
#include "TObject.h"
class MyClass : public TObject
{
public:
MyClass() : TObject(), fInt(0) {}
template <typename T>
MyClass(T input) : TObject() { fInt = static_cast<Int_t>(input); }
template <typename T>
void SetInt(T input) { fInt = static_cast<Int_t>(input); }
Int_t fInt;
ClassDef(MyClass, 1)
};
ClassImp(MyClass)
The LinkDef file I wrote for this (where, for the sake of simplicity, I figure input will be just Int_t and Double_t) is:
// LinkDef.h
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;
#pragma link C++ class MyClass;
#pragma link C++ function MyClass::MyClass(Int_t);
#pragma link C++ function MyClass::MyClass(Double_t);
#pragma link C++ function MyClass::SetInt(Int_t);
#pragma link C++ function MyClass::SetInt(Double_t);
#endif
I try to create a library for this object, and get:
$ rootcint -f Dict.C -c -I`root-config --incdir` MyClass.h
$ g++ `root-config --cflags` `root-config --ldflags` -fPIC -shared -o Dict.so Dict.C
In file included from Dict.h:34:0,
from Dict.C:17:
MyClass.h: In constructor ‘MyClass::MyClass(T) [with T = TRootIOCtor*]’:
Dict.C:138:53: instantiated from here
MyClass.h:8:36: error: invalid static_cast from type ‘TRootIOCtor*’ to type ‘Int_t’
When I remove the templated constructor from MyClass.h and LinkDef.h, the code compiles; however, attempting to use the SetInt function, I get:
root [0] gSystem->Load("Dict.so")
(int)0
root [1] MyClass c
root [2] Int_t i = 2
root [3] Double_t d = 4.5
root [4] c.SetInt(i)
Error: Can't call MyClass::SetInt(i) in current scope (tmpfile):1:
Possible candidates are...
(in MyClass)
*** Interpreter error recovered ***
root [5] c.SetInt(d)
Error: Can't call MyClass::SetInt(d) in current scope (tmpfile):1:
Possible candidates are...
(in MyClass)
*** Interpreter error recovered ***
Any help on this would be greatly appreciated!
Thanks,
Clayton
PS. I am using the v5-28-00-patches branch of ROOT, revision 39785 (June 16, 2011).