I have a template class, implemented in a classic C++ way and I want to add it to the root dictionary to be able to store objects from this class into root files. I saw in the manual that I have to add this line :
in the linkdef file for each type I want to use with my class. I also added the ClassDef macro in the declaration of this class but I still have dictionary generation errors. Are there other steps to perform for templates?
No this should be it (and even the ClassDef is optional (but improve performance). What is the error messages? Also you need to make sure that the dictionary file is including the header file of the class uses as parameter, for this you might need to use
#pragma extra_include "TString.h"
Actually in my class I made some template members and I use this syntax
void myFunction(T2* param);
So, I just removed the first line and changed the T2 in T and it works now.
But I have a new problem. I added a template member in another class which has to return an objects from my template class like it:
but that generate a segmentation fault at the dictionary generation. Have I to added this function to the linkdef file? And if yes, how?
[quote]So, I just removed the first line and changed the T2 in T and it works now[/quote]This is a big change of your code (aka you get 2 totally different result. Are you intending on ‘myFunction’ to always take the same parameter type of the class or to allow it to be able to take ANY possible type? Same question for myFunction2.
If you meant that have a templated member function [your first syntax] as oppose to a member function of a templated class [your second syntax], you must also request explicitly the instantiation you want in the linkdef (because rootcint can not guess your second argument!)
[This post was corrected to replace ‘class’ with ‘function’ in the code sample.]
Yes I know that it is not the same result or at least it reduce the type that can be accepted by the function at the class template type.
Concerning the second problem I’m not sure I understand your answer. I have my function declared in my class as I showed before ie :
and implemented outside my class(of course in the same file) like that :
Where myClass is my non template class which has a template function.
How can I add this function to the linkdef file?
#pragma link C++ function myClass::myFunction2<int>();