i’m used to write templates like this:
template<typename T>
void someFunction(SomeClass<T> argument);
however – now I encountered templates in another thread written like this:
template<U>
void someFunction(SomeClass<U> argument);
as far as i know one can use “typename” and “class” interchangably (except for some details regarding nested types..). but what does it mean if i don’t put a keyword in the brackets at all?
thanks!
the thread in question:
Problems writing a copy constructor for a smart pointer
That code is wrong (typo). There must be a
typenameorclassin this situation.classcompiles.error: ‘U’ has not been declared.However, it does not mean that all template parameters must start with a
typename/class. This is because besides types, a template parameter can also be integral constants, so the following code works:and so is the following:
This is why I asked if
Uis a typedef in the comment.