こう?
template <typename T> friend B<T> h(const B<T> & x, const A & y);
↓
template <typename T> B<T> friend h(const B<T> & x, const A & y);