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.
private
                                             Up Contents Index Back
─────C/C++ Language─────────────────────────────────────────────────────────
 
  Keyword:   private
 
  Syntax:    private: [member-list]
             private base-class
 
  Summary:   When preceding a list of class members, specifies that
             those members are accessible only from member functions and
             friends of the class. Applies to all members declared up to
             the next access specifier or the end of the class.
 
             When preceding the name of a base class, specifies that
             the public and protected members of the base class are
             private members of the derived class.
 
  See also:  friend, public, protected
             Table of Access Privileges
 
     Default access of members in a class is private. Default access of
     members in a structure or union is public.
 
     Default access of a base class is private for classes and public
     for structures. Unions cannot have base classes.
 
     Example
 
         class BaseClass
         {
         public:
             // privMem accessible from member function
             int pubFunc() { return privMem; }
         private:
             void privMem;
         };
 
         class DerivedClass : public BaseClass
         {
         public:
             void usePrivate( int i )
                 { privMem = i; }   // Error: privMem not accessible
                                    //    from derived class
         };
 
         class DerivedClass2 : private BaseClass
         {
         public:
             // pubFunc() accessible from derived class
             int usePublic() { return pubFunc(); }
         };
 
         void main()
         {
             BaseClass aBase;
             DerivedClass aDerived;
             DerivedClass2 aDerived2;
 
             aBase.privMem = 1;     // Error: privMem not accessible
             aDerived.privMem = 1;  // Error: privMem not accessible
                                    //    in derived class
             aDerived2.pubFunc();   // Error: pubFunc() is private in
                                    //    derived class
         }
                                    -♦-