Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views1 page

Inheritance 5

The document explains the visibility modes in C++ inheritance, detailing how private, public, and protected inheritance affect member accessibility in derived classes. It includes a summary table illustrating the visibility changes for each type of inheritance. Additionally, it lists ways to access private and protected members, and poses questions for student activities related to inheritance concepts.

Uploaded by

josephwelch042
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Inheritance 5

The document explains the visibility modes in C++ inheritance, detailing how private, public, and protected inheritance affect member accessibility in derived classes. It includes a summary table illustrating the visibility changes for each type of inheritance. Additionally, it lists ways to access private and protected members, and poses questions for student activities related to inheritance concepts.

Uploaded by

josephwelch042
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

cout « "\n \n";

ml.show ( );
}

Making a Private Member Inheritable


Basically we have visibility modes to specify that in which mode you are deriving the another class
from the already existing base class. They are:

a. Private: when a base class is privately inherited by a derived class, 'public


members' of the base class become private members of the derived class and
therefore the public members of the base class can be accessed by its own
objects using the dot operator. The result is that we have no member of base
class that is accessible to the objects of the derived class.
b. Public: On the other hand, when the base class is publicly inherited, 'public
members' of the base class become 'public members' of derived class and
therefore they are accessible to the objects of the derived class.
c. Protected: C++ provides a third visibility modifier, protected, which serve a
little purpose in the inheritance. A member declared as protected is accessible
by the member functions within its class and any class immediately derived
from it. It cannot be accessed by functions outside these two classes.

The below mentioned table summarizes how the visibility of members undergo modifications when
they are inherited

Base Class Visibility Derived Class Visibility


Public Private Protected
Private X X X
Public Public Private Protected
Protected Protected Private Protected

The private and protected members of a class can be accessed by:


a. A function i.e. friend of a class.
b. A member function of a class that is the friend of the class.
c. A member function of a derived class.
Student Activity
1. Define Inheritance. What is the inheritance mechanism in C++?
2. What are the advantage of Inheritance?
3. What should be the structure of a class when it has to be a base for other classes?

You might also like