Hi. My question is, how do you make a function in another class friend of the class you're in?
I mean that i can make a global function friend of a class, as:
Code:
class X {
   friend void friend_func(X*, int);
private:
   int i;
public:
   void member_func(int);
};

void friend_func(X* xptr, int a) { xptr–>i = a; }  /* this has access to X.i */
It works if friend_func(,) does not belong to any class, but if I want to make a friend function from another class I can't make it;
besides, i wouldn't like to make the whole class friend.

Code:
class X {
   friend void Y::friend_func(X*, int);
private:
   int i;
public:
   void member_func(int); //blah blah 
};

class Y {
public:
   void friend_func(X*, int);
// stuff...
};
I can't put Y in front of X 'cos i need X instances in Y.

How do i gain access from Y::friend_func(...) to X? It won't work, even if i declare the class at the beginning as

Code:
class Y;
class X {
   friend void Y::friend_func(X*, int);
};
class Y {
   void friend_func(X*, int);
};
neither

Code:
class Y {void friend_func(X*,int);};
class X {
   friend void Y::friend_func(X*, int);
   // ... stuff... 
};
class Y {
   // the rest of Y here
};
'cause then i get multiple declaration error, and if i don't do it, i get friend_function is not a member of... although it is declared afterwards.

any hints?
thanks alot