CONCLUSION: Yes, but Intellisense won't like it as of VC++ 11.0.60610.01
I generally don't use friendship, but this time I really need it, and I can't get it to work in Visual Studio 2012. I think it might be an intellisense bug (the code compiles fine) but I just wanted to see if there was something wrong with my code. This reproduces the problem:
class B;
class A
{
public:
int fun(B b);
};
class B
{
public:
friend int A::fun(B b);
B() : member(0) {}
private:
int member;
};
int A::fun(B b)
{
return b.member; // Error: B::member is inaccessible.
}
int main()
{
A a;
B b;
std::cout << a.fun(b);
return 0;
}
The above code compiles fine on codepad but returns an Intellisense error in VS2012. Is there something I'm doing wrong?