Several template functions inside a class without a template

I have a class foothat contains two template functions Add()and Subtract().

struct foo
{
    template <typename U>
    U* Add();
    template <typename U>
    U* Subtract();
};

Is it right to use the same template parameter Ufor both of them? Also do I need to write template <typename U>every time before declaring a template function?

+4
source share
1 answer

Yes, you can use the same name for template parameters in different functions, just as you can call arguments the same. These names are not completely related in different functions.

And yes, you should use the keyword templateaccording to C ++ grammar.

+7
source

Source: https://habr.com/ru/post/1690712/


All Articles