In order to declare a function as a friend, the compiler has to have seen it first, and C++ does not allow forward declarations of member functions. Therefore what you are trying to do is not possible in the way you want. You could try using the "passkey" method from here.
Alternatively, you could replace void friend Y::f(X* x);
with friend class Y;
.