F
Frank Schmitt
Hi!
Suppose I have a class template Foo
with a member function template bar - so far so good:
template <typename T>
struct Foo {
template <typename U>
void bar(const U& u);
};
No problem so far. Now, I want to define bar. This doesn't work:
template <typename T, typename U>
void Foo<T>::bar(const U& u) {
}
It cost me half an hour of trial-and-error to find out
that this does work:
template <typename T> template <typename U>
void Foo<T>::bar(const U& u) {
}
I thought U was just an additional template parameter,
but it seems like two nested template declarations are needed -
why ?
thanks in advance & kind regards
frank
Suppose I have a class template Foo
with a member function template bar - so far so good:
template <typename T>
struct Foo {
template <typename U>
void bar(const U& u);
};
No problem so far. Now, I want to define bar. This doesn't work:
template <typename T, typename U>
void Foo<T>::bar(const U& u) {
}
It cost me half an hour of trial-and-error to find out
that this does work:
template <typename T> template <typename U>
void Foo<T>::bar(const U& u) {
}
I thought U was just an additional template parameter,
but it seems like two nested template declarations are needed -
why ?
thanks in advance & kind regards
frank