C++ Resources

Updated on Nov 1  2020



C++OOPInheritance

Deborah R. Fowler



OOP Inheritance for C++  

Posted on Oct 19  2019
Updated Oct 20  2019
 
This section assumes you have read the basics of OOP for C++ and pointers.



INHERITANCE

Inheritance is similar to a linux directory structure and is often drawn as a tree. A class can inherit properties from another. The child class (derived) inherits the properties of the parent (base) class.

Suppose that we have a class called Phone, now we want to have a child class of Phone that has all the properties of the parent but additional properties. For example:

MISSING IMAGE
A phone allows us to communicate and has a provider however there can be different types of phones.
MISSING IMAGE
What does this looks like in code?
To indicate inheritance the syntax is class Child : accesstype Parent
MISSING IMAGE


Access Level

Let's talk about accesstype for data.There are three choices for access level

MISSING
            IMAGE

Now what about protected?

MISSING IMAGE



You can also have multiple inheritance - click on the image for an example file.
MISSING IMAGE

Next up - Splitting into multiple files