C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Friend Functions
                                             Up Contents Index Back
─────C/C++ Language─────────────────────────────────────────────────────────
 
     A friend function is a function that is not a member of a class but
     has access to the class's private and protected members.
 
     A friend function is declared by the class that is granting access.
     For example:
 
         class Complex
         {
         public:
             Complex( float re, float im );
             friend Complex operator+( Complex first, Complex second );
         private:
             float real, imag;
         };
 
     The friend declaration can be placed anywhere in the class
     declaration. It is not affected by the access control keywords.
 
     A friend function is defined as a nonmember function. For example:
 
         Complex operator+( Complex first, Complex second )
         {
             return Complex( first.real + second.real,
                             first.imag + second.imag );
         }
 
     In this example, the friend function operator+ has access to the
     private data members of the Complex objects it receives as
     parameters.
 
     Notice that the friend keyword does not appear in the function
     definition.
                                    -♦-