I can use partial specialization of templates inside a class declaration
template<class T1, class T2> struct A { void foo() { cout << "general"; } }; template<class T1> struct A<T1, int> { void foo() { cout << "partial specialization"; } };
But when I try to do this outside the class declaration
template<class T1, class T2> struct A { void foo(); }; template<class T1, class T2> void A<T1, T2>::foo() { cout << "general"; } template<class T1> void A<T1, int>::foo() { cout << "partial specialization"; }
I get the following error:
invalid use of incomplete type "struct A <T1, int>"
You should not use the first approach when you want to redefine all members, but what if you want to redefine only one method without code duplication for all others?
So, is it possible to use the partial template specification outside the class definition?
source share