class A { friend class B; private: int x; int y; void fnA(int v) { cout << "Called function A with v=" << v << endl; } public: A(int x, int y) { this -> x = x; this->y = y; } void publica(int v) { cout << "called public A with v=" << v << endl; } }; class B { friend class A; private: int a; int b; void fnb(int v){ cout << "Called function b with v=" << v << endl; } public: B(int a, int b) { this->a = a; this->b = b; } void publicb(int v) { cout << "called public b with v=" << v << endl; } // This function can access private members of A void showA(A *a) { cout << "Var x from class A=" << a->x << endl; } }; // Code to show how this works. A testa(2, 3); B testb(6, 7); testb.publicb(11); testb.showA(&testa);