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.

-- 
           Summary: Friend declaration of a private member function produces
                    error in g++-4.0
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fjahanian at apple dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: apple-ppc-darwin
  GCC host triplet: apple-ppc-darwin
GCC target triplet: apple-ppc-darwin


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22009

Reply via email to