Partial specialisation
Hi,
The following code is legal, and works as expected:
#include <iostream>
template <typename T>
class Bar {
};
template <typename T, typename P>
class Foo {
public:
void doStuff();
};
template <typename T, typename P>
void Foo<T, P>::doStuff() {
std::cout << "General" << std::endl;
}
int main() {
Foo<float, Bar<float> > a;
a.doStuff();
Foo<float, float> b;
b.doStuff();
return 0;
}
But none of these specialise the method doStuff():
// Not valid:
template <typename T>
void Foo<T, Bar<T> >::doStuff() {
std::cout << "Specific" << std::endl;
}
// Not valid:
template <typename T, typename P=Bar<T> >
void Foo<T, P>::doStuff() {
std::cout << "Specific" << std::endl;
}
// Not valid:
template <typename T, Bar<T> >
void Foo<T, Bar<T> >::doStuff() {
std::cout << "Specific" << std::endl;
}
Is there a valid way to achieve this without using a non member template
function and calling that from within the generic doStuff()?
Thanks,
Alan