I have the following minimal example:
class A
{
template<typename X, typename Y>
void f()
{ }
template<>
void f<int, char>()
{ }
};
The compiler gives an error message
explicit specialzation in non-namespace scope.
Why is this wrong and how can I fix it?
§14.7.3 [temp.expl.spec]/p2:
An explicit specialization shall be declared in a namespace enclosing the specialized template.
So you need to move the specialization outside A
's definition:
class A
{
template<typename X, typename Y>
void f()
{ }
};
template<>
void A::f<int, char>()
{ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With