According to the C++ Primer book, the author mentioned that We can specify a class member function as a friend of another class, instead of the entire class (page 634).
firstly forward declare class A, so that its visible in class B definition. then define class A containing a friend function from class B.