Forward declaration of template friend function
问题 Consider the following code snippet that works perfectly fine: class A { private: int d; public: A(int n){ d = n;} friend int foo(A a); }; int foo(A a) { return a.d; } However, when I try to use a template for the class, I need to forward declare the friend function for it to run, as follows: template <typename T> class B; template <typename T> T foof(B<T> a); template <typename T> class B { private: T d; public: B(T n){ d = n;} friend T foof<>(B<T> a); }; template <typename T> T foof(B<T> a)