我无法通过模板及其所有部分专业化来使课程成为朋友。是否有任何特定的技巧可以实现这一点或我不知道的一些限制?
答案 0 :(得分:2)
class Y{
template<class T>
friend class X; // friends all instantiation forms of X
void a_private_func() const{}
};
template<class T>
class X{
public:
void f(Y const& y){ y.a_private_func(); }
};
template<class T>
class X<T*>{
public:
void g(Y const& y){ y.a_private_func(); }
};