SG said:
You mean "function template" and "class template".
Yes. I meant that.
yes. It's something along the lines of
template<typename T>
template<int N>
void S<T>::foo(int k) {}
template<typename T>
template<>
void S<T>::foo<0>(int k) {}
I have tried something as below:
//------------------------------------
#include <iostream>
template<class T> class A {
public:
template<size_t N> void f();
};
template<class T> template<size_t N> void A<T>::f() {
std::cout << N << std::endl;
}
template<class T> template<> void A<T>::f<0>() {
std::cout << "Stopping ..." << std::endl;
}
int main() {
A<int> a;
a.f<10>();
a.f<0>();
}
//------------------------------------
test2.cpp:10: error: invalid explicit specialization before '>' token
test2.cpp:10: error: enclosing class templates are not explicitly
specialized
test2.cpp:10: error: template-id 'f<0>' for 'void A<T>::f()' does not
match any template declaration
Well, as I found there was no matching f<0> to anything, I added
declaration in the class template, so appart from the class definition,
everything looks the same in the code:
//-------------------------------------
#include <iostream>
template<class T> class A {
public:
template<size_t N> void f();
template<> void f<0>();
};
template<class T> template<size_t N> void A<T>::f() {
std::cout << N << std::endl;
}
template<class T> template<> void A<T>::f<0>() {
std::cout << "Stopping ..." << std::endl;
}
int main() {
A<int> a;
a.f<10>();
a.f<0>();
}
//-------------------------------------
but it looks even worse:
test2.cpp:6: error: explicit specialization in non-namespace scope
'class A<T>'
test2.cpp:11: error: invalid explicit specialization before '>' token
test2.cpp:11: error: enclosing class templates are not explicitly
specialized
test2.cpp:11: error: template-id 'f<0>' for 'void A<T>::f()' does not
match any template declaration
So what do you think I am doing wrong here?
Cheers!
Ziko