Use template in a macro


I want to create a C-macro with a method that receives a template class. It is this possible?

template <class T>

Int_t MyMethod( T* cPointer )
// Do whatever with T* 

A simple macro including this seems to load without errors into ROOT command interface using .L. However, later on the method is not recognised, not autocompleted.


Well, this works for me:

template <class T>
T tfunc(T v)
   T x = v;
   std::cout << "x = " << x << std::endl;
   return x;
[bellenot@bbcc7x64 rootdev]$ root -l
root [0] .L template.C
root [1] int d = 9;
root [2] tfunc(d)
x = 9
(int) 9
root [3]

Ok, it works for me too.

I didn’t realise it was working because the function is not autocompleting using TAB key.

So, if I write on ROOT console tfu and press TAB key several times, it will not autocomplete or offer any suggestions. Thats why I thought the method was not loaded. When I execute tfunc once, the method with the integer version exists, and autocompletes.

Personally, this is not convenient if I want to check the methods that are available/loaded. Even if they use a generic template.

OK, so maybe @Axel can comment on this one…

That’s now and - thanks for reporting!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.