The code
template <typename T>
void foo(const T& t)
{}
template <typename T>
class A
{
template <>
friend void foo<T>(const T& t)
{}
};
gives compile error
"defining explicit specialization ‘foo<T>’ in friend declaration friend void foo<T>(const T& t)"
when compiling with gcc and
"error C3637: 'A<int>::foo' : a friend function definition cannot be a specialization of a unction template"
when compiling in VS2013
I understand that standard says so, but why? I want to understand the reason(under the hood) There are many articles where written "An explicit specialization cannot be a friend declaration.", but I can't understand why. Any ideas?
explicit specialization in non-namespace scope 'struct A<T>'
andtemplate-id 'foo<T>' in declaration of primary template
for the given code. – OsunaA
for a new set of template arguments, you'd add another explicit specialization offoo
. It is ill-formed, No Diagnostic Required, to add that specialization iffoo
has already been implicitly instantiated for the same template arguments [temp.expl.spec]/6. – Clubfoot