Inheritance is a powerful concept in C++ that allows us to inherit all of the member functions and the data from a base class into a derived class. What this means is we can create more generic data structures that allow us to build specific and specialized data structures, without having to rewrite this logic. For example, if we think about a cube class so far, the cube is really just say, specific version of a shape, and there may be some functionality that's true about every single shape. Like every two-dimensional or even one-dimensional shape, has a length, and that length can be shared between a cube, a rectangle, and a number of other shapes. So, thinking about our base class, the base class is just like our class cube except here, in our shape class, we have a public section just like the cube class in a private section, and here the shape class has a constructor and has a one parameter constructor and has a getWidth function that's going to allow us to access this underlying width variable. Notice we don't have getSurfacearea, getVolume, these are things that are specific to the cube itself. But instead we have only the basic things that are shared between many different shapes. Here in our cube class, we now see, we've added an additional few pieces to this class.h file. First, notice that we're now including our base class shape.h, and the way we can declare that shape is the base class is by putting colon immediately follow on class name, followed by public and then the name of our base class. So, here we would read line 14 as the class cube inherits the class shape. Everything we're going to do in this course is going to always be public inheritance. We're always going to see the word public here, and 99% of the use of inheritance is usually public inheritance. After that, we see that we have the definition of functionality specific for our cube. Here we have a cube constructor that has its width and has its color thinking back from the tower paranoid cube. On line 17 we have getVolume, which allows us to get the volume of the cube, that's going to be something specific to the cube itself. Because our shape doesn't have a color and only a cube has a color, we're going to store the color here in the private section, but the actual width of the length of the cube is covered in our base class. So, we don't need to include a length here inside of our cube. When we initialize a derived class, we must initialize the base class. So, you can't simply construct a cube that's been derived from a base class of a shape without constructing the shape as well. So the cube must construct a shape and by default the cube is going to use the shapes default constructor. We can use custom constructors by using something called the initialization list. So, let's look at the CPP file for a cube, and here in our cube we see we have the cube constructor, and our cube constructor takes in two parameters. It takes in a width and it takes in a color. Because we want to give a shape with a specific width, we're going to use the initializer list syntax. So, after the end of our function declaration, I have a colon followed by the name of my base class. So, I'm asking C++ to initialize the shape class by using the shape constructor that takes in the width as a parameter. Then my logic unique to the cube classes here on line 13. What happens here is the first thing we're going to do is we're going to initialize a shape itself. We're going to create a shape that has a length of whatever with this and then we're going to add all the cubes specific logic. So, the shape gets constructed first and then the cube gets constructed second. There's an interesting bit here on line 16 through 20, where we have a double getVolume function that's inside of a cube and this getVolume function normally we did width times width times width. Instead, we need to call the getWidth function because the width variable is actually a private member of a different class. It's a private member of shape and not a private member of the cube. Since it's a private member of another class, we don't have access to it. Instead, we need to call the accessor method to getWidth method to return that variable for us. That gets to the idea of access control. When a base class inherited, we can access all of the public members of the base class, but we cannot access any of the private members of the base class. So, anything that's private can only be accessed by the class itself not even the derived class. That initializer list syntax that we introduced earlier to call a custom default constructor for our base class, is used quite a bit in C++ and we can do a lot of awesome things with it. So, in addition to initialize in the base class, we can use initializer list to initialize the current class via another constructor. So, if we want to delegate all of the work to a different construct or we can do that, and we can initialize default values and member variables. So, initializer list allows us to initialize not just which base class is called, but which secondary constructors called for us as well as default values for variables. So, for example, if we look at the shape that CPP constructors, we see that in the shape itself, so remember this is the base class, the basic shape constructor, this is the default constructor here, is going to call the one parameter constructor with a width of one. So, what's happening here is the default constructor of shape is using the logic in the one parameter of constructive shape to initialize our object, and it's specifically passing and we want a width one shape. In our one parameter constructor, we see we have an initializer list here and it initializes the private member variable width to the value that's passed in as width. So, through the use of initializer list, we were able to initialize the default constructor with a one parameter constructor, and then our one parameter constructor initialize private member variables without ever having to do anything in the code itself. It's also a way to clean up our code into reuse a lot of our code, so we have only a single constructor through the entire process. So, let's go ahead and look at the program and see how this works when we run a main program. Going into the CPP inheritance directory, going through unmake, and let's look at what main.cpp does. Main.cpp is going to create a cube of width four that's purple, and print out that we've created a custom cube. This is using the cube that we created that is a derived class of the shape. So, if I run dot slash main, we see indeed we create a purple cube and we do that through building a shape that has a length of four and then creating cube as a derived class from the base class I've shaped. As we build more and more data structures, we're going to start building small pieces that we can inherit from to build bigger and bigger systems and more complicated data structures without having to think of all of logic. So, I look forward to working with you guys as we build this thing up. I'll see you then.