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
template<class T2>
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:
template<class T>
Entry<T>* myFunction2();
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!)
Cheers,
Philippe.
[This post was corrected to replace ‘class’ with ‘function’ in the code sample.]