I am currently reading a book on C++ , and it has some exercises. In one of the exercises, it is proposed to build two classes, where each of them has a friend method for the other. My current hunch looks like this:
#include <iostream> using std::cout; using std::endl; class Y; class X{ public: void friend Y::f(X* x); void g(Y* y){cout << "inside g(Y*)" << endl;} }; class Y{ public: void friend X::g(Y* y); void f(X* x) {cout << "inside f(X*)" << endl;} };
But my hunch is not compiled, because class X has a declaration of the void friend Y::f(X* x); method void friend Y::f(X* x); . How can I solve the puzzle? Give me some more guesses, please.
source share