Reputation: 185
I have a class foo
which contain two template functions Add()
and Subtract()
.
struct foo
{
template <typename U>
U* Add();
template <typename U>
U* Subtract();
};
Is it correct to use same template parameter U
for both of them? Also do I need to write template <typename U>
every time before a template function declaration?
Upvotes: 4
Views: 136
Reputation: 62553
Yes, you can use the same name for template parameters in different functions, the same way you can name arguments the same. Those names in different functions are completely unrelated.
And yes, you have to use keyword template
as per C++ grammar.
Upvotes: 7