Making a static member function a friend

I have the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class A {
	int x;
	friend static int B::DoIt(A& a);
	friend int DoIt2(A& a);
};

class B {
	static int DoIt(A& a);
};

int B::DoIt(A& a)  {
	return a.x; //can't access a.x
}

int DoIt2(A& a) {
	return a.x;
}


It's easy to declare DoIt2 as a friend of A, but how do I declare B::DoIt(A& a) as a friend of A? I can't seem to find the right syntax for doing it.
No need for the static in A and you will need to define B before it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class A;

class B {
public:
	static int DoIt(A& a);
};

class A {
	int x;
	friend int B::DoIt(A& a);
	friend int DoIt2(A& a);
};

int B::DoIt(A& a)  {
	return a.x;
}

int DoIt2(A& a) {
	return a.x;
}
Wow. Apparently VS's intellisense was lying to me, it compiled just fine. Thanks.
Topic archived. No new replies allowed.