Overriding Access in Inheritance


The inherited access to members of a base class by members or objects of a derived class may seem too restrictive when applied to all base class members. Fortunately, it is possible to override extension access to specific base class members. The inherited access can be overridden so that access by members or objects of a derived class is no more restrictive than access to the base member by a base member or a base object.

To override the inherited access, the programmer places a declaration of the base member in the derived class access section desired using the access scope resolution operator as in:

image from book

 access_specifier:   base::the_member; 

image from book

For example: higherac.cpp

In inheritance the question arises: Can members be raised above the access level that they had in the base class? The answer is no. That is the accessSpecifier of the derived class may be no less restrictive than the accessSpecifier used for theMember in the base class. For an example see: devi.cpp




Intermediate Business Programming with C++
Intermediate Business Programming with C++
ISBN: 738453099
EAN: N/A
Year: 2007
Pages: 142

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