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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With