How can I create a dictionnary for template functions? Say I have this template function:
template <class T>
void printVector(const std::vector<T>& a)
{
for (size_t i = 0; i < a.size(); ++i) {
std::cout << a[i] << " ";
}
std::cout << std::endl;
return ;
}
What should I do in my LinDef.h file if I want to generate dictionnaries for, say “int” and “float”?
I tried
#ifdef __CINT__
#pragma link C++ function printVector(const std::vector<float>& a);
#pragma link C++ function printVector(const std::vector<int>& a);
#endif
but it doesn’t work. I also tried “#pragma link C++ function printVector(const std::vector& a);” but it doesn’t work either.
This is due to one of the deficiencies of CINT that we hope to fix later this year in the way it deal with the std namespace. To work around this issue, declare the template as:
#ifdef __CINT__
template <class T>
void printVector(const vector<T>& a)
#else
template <class T>
void printVector(const std::vector<T>& a)
#endif
This is due to one of the deficiencies of CINT that we hope to fix later this year in the way it deal with the std namespace. To work around this issue, declare the template as:
#ifdef __CINT__
template <class T>
void printVector(const vector<T>& a)
#else
template <class T>
void printVector(const std::vector<T>& a)
#endif
[/quote]
This is no longer a root issue, but since templates definitions are usually '#include’d, they should follow header file style rules. ‘using namespace std;’ is usually strongly discouraged (and even if it’s not, you are free to use the std:: identifier.
In other words
template <class T>
void printVector(const std::vector<T>& a)
should be sufficient in all cases and preferable in most.