I think following test case is correct. But g++-4.0 produces a diagnostics. We should be able to declare a private member function of a class as a friend of another class in order for the member function be able to access private members of the befriended class. class FriendTestTo; class FriendTestFrom { private: void reallySetIt (FriendTestTo* PF); }; class FriendTestTo { private: int i; friend void FriendTestFrom::reallySetIt (FriendTestTo*); }; void FriendTestFrom::reallySetIt (FriendTestTo* PF){ PF->i = 1; }; % g++ -c test.cc test.cc:6: error: 'void FriendTestFrom::reallySetIt(FriendTestTo*)' is private test.cc:13: error: within this context Workaround is to declare class FriendTestFrom as friend of class FriendTestTo.
The code is invalid. See DR 209 which was closed as not a defect. http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_closed.html#209 This is a dup of bug 7809 which changed the behavior of GCC to match the standard. *** This bug has been marked as a duplicate of 7809 ***