public

protected

The protected access specifier declares members that are private to a class but that can be inherited by a derived class. It has the following general form:

 class class-name {      // ... protected: // make protected      // protected members };

For example,

class base {   // ... protected:   int a;   // ... }; // Now, inherit base into derived class. class derived : public base {   // ... public:   // ...   // derived has access to a   voidf() { cout << a; }  };

Here, a is private to base and cannot be accessed by any nonmember function. However, derived inherits access to a. If a were simply defined as private, derived would not have access to it.

When used as an inheritance specifier, protected has this general form:

class class-name : protected base-class { // ...

By specifying a base class as protected, all public and protected members of the base class become protected members of the derived class. In all cases, private members of the base class remain private to that base.




C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net