class Y{
  template<class T>
  friend class 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(); }
};

int main(){
  X<int> xi;
  X<int*> xpi;
  Y y;
  xi.f(y);
  xpi.g(y);
}