Why does gcc give an error?
[Error] specialization of 'template class A' must appear at namespace scope
template<class T1, class T2> class A { template<class T3> friend class A<T1, T3>; }; Why does gcc give an error?
[Error] specialization of 'template class A' must appear at namespace scope
template<class T1, class T2> class A { template<class T3> friend class A<T1, T3>; }; In C ++, it is not possible to use partial specialization in order to “outline” only a subset of the template specializations as friends.
14.5.4 Friends
8 Friend declarations partial declarations. [Example:
template<class T> class A { }; class X { template<class T> friend class A<T*>; // error }; —End example]
That is, a friend can be either a template (with all its specializations) or a specific specialization (that is, full specialization) of a template.
std::is_same ? - user230240Remove <T2> :
template<class T> class A { template<class T2> friend class A; }; Update:
well ... again -
template<class T1, class T3> friend class A; However, it is not very sure that it will work specialization.
T1 ), while others have changed ( T2 -> T3 ) - user230240Source: https://ru.stackoverflow.com/questions/600380/
All Articles