C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Friend Classes
                                             Up Contents Index Back
─────C/C++ Language─────────────────────────────────────────────────────────
 
     A friend class is a class all of whose member functions are friend
     functions of a class, i.e., whose member functions have access to
     the other class's private and protected members.
 
     For example:
 
          class YourClass
          {
          friend class YourOtherClass;  // Declare a friend class
          private:
              int topSecret;
          };
 
          class YourOtherClass
          {
          public:
              void change( YourClass yc );
          };
 
          void YourOtherClass::change( YourClass yc )
          {
              yc.topSecret++;    // Can access private data
          }
 
     Friendship is not mutual unless explicitly specified as such. In
     the above example, member functions of YourClass cannot access the
     private members of YourOtherClass.
 
     Friendship is not inherited, meaning that classes derived from
     YourOtherClass cannot access YourClass's private members; nor
     is it transitive, so classes that are friends of YourOtherClass
     cannot access YourClass's private members.
                                    -♦-