Environment: Microsoft Visual Studio 2010
Coding standard: C++0x compatible
I have a class template
template <typename T1, int I>
class A
{
public template <typename T2> void f(T2 x);
/*...*/
};
template <typename T1, int I>
template <typename T2>
void A<T1, I>::f(T2 x)
{
/*...*/
}
and partial specialization of above class
template <int I>
class A<char, I>
{
public template <typename T2> void f(T2 x);
/*...*/
};
Then can I specialize member function in the partially specialized class like below?
template <int I>
template <>
void A<char, I>::f<double>(double x)
{
}
Thanks!
NB: I’m not working on it but thinking if it’s applicable or not. Easy rating if you know about the rule.
This is invalid because you cannot explicitly specialize a member function without also giving fixed template arguments to any enclosing class template.
Not C++11 compatible, but working on MSVC
The Microsoft compiler has an extension that allows to declare explicit specializations within class templates though. Even though I have never tried it, chances are good that it will accept the following non-standard code
Update: Clang compiles this and reports
C++11/C++03 compatible
The way here is overloading instead of specialization