Explicit Specialization Cannot Be Friend Declaration

The code

template <typename T>
void foo(const T& t)
{}

template <typename T>
class A
{
    template <>
    friend void foo<T>(const T& t)
    {}
};

gives a compilation 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 the standard says so, but why? I want to understand the reason (under the hood) There are many articles that say: “Explicit specialization cannot be a friend’s declaration”, but I can’t understand why. Any ideas?

+4
source share
1 answer

(, , ) , "" - , . , , -, ; - , @dyp , [temp.expl.spec]/6

, ADL. , , , - , ODR.

​​ , : friend, , .

friend void foo<T>(const T&);

​​ .

+3

Source: https://habr.com/ru/post/1569892/


All Articles