C ++ templates without "typename" or "class"
I use to write patterns like this:
template<typename T>
void someFunction(SomeClass<T> argument);
however - now I came across templates in another thread written as follows:
template<U>
void someFunction(SomeClass<U> argument);
as far as I know, you can use "typename" and "class" interchangably (with the exception of some details regarding nested types ..). but what does it mean if I don't put the keyword in brackets at all?
thank!
thread in question: Writing copy constructor problems for smart pointer
This code is incorrect (typo). In this situation should be typenameor class.
, typename/class. , , :
// template <int n>, but n is not used, so we can ignore the name.
template <int>
void foo(std::vector<int>* x) {
}
int main () {
foo<4>(0);
}
:
typedef int U;
// template <U n>, but n is not used, so we can ignore the name.
template <U>
void foo(std::vector<U>* x) {
}
int main () {
foo<4>(0);
}
, U typedef .