You should read the MSDN article about this issue: Class Member Functions and Classes as Friends
Basically what you need to do is have a class type A
with a function f()
, and then you declare in class type B
that there exists a function A::f()
which will be your friend.
The MSDN example shows this well:
class A {
public:
int Func1( B& b );
private:
int Func2( B& b );
};
class B {
private:
int _b;
// A::Func1 is a friend function to class B
// so A::Func1 has access to all members of B
friend int A::Func1( B& );
};
int A::Func1( B& b ) { return b._b; } // OK
int A::Func2( B& b ) { return b._b; } // C2248