1
00:00:00,210 --> 00:00:00,570
OK.

2
00:00:00,600 --> 00:00:06,690
Welcome to another lecture, and we are going to go over a new topic in this lecture, and that topic

3
00:00:06,690 --> 00:00:08,610
is going to be inheritance.

4
00:00:10,740 --> 00:00:17,880
So sometimes we want to design our programs around the idea of a relationship between different abstract

5
00:00:17,880 --> 00:00:20,220
data types, which I referred to as 80s.

6
00:00:20,250 --> 00:00:24,750
These are user defined data types just like our car class and we've been using.

7
00:00:25,410 --> 00:00:33,600
So speaking of the car class, if we use that as an example, we might also want to create some new

8
00:00:33,600 --> 00:00:36,420
classes for different subtypes of cars.

9
00:00:37,200 --> 00:00:42,330
So think about something like trucks, sedans, SUVs, right?

10
00:00:42,450 --> 00:00:44,070
Those are all types of cars.

11
00:00:44,460 --> 00:00:52,350
The relationship between a car and each of these subtypes can be defined as an is a relationship.

12
00:00:52,530 --> 00:00:57,540
So a truck is a car, a sedan is a car and an SUV is a car.

13
00:00:57,550 --> 00:01:03,420
And this is very important because this type of relationship will drive the way we arrange and use our

14
00:01:03,420 --> 00:01:05,100
classes in our program.

15
00:01:05,520 --> 00:01:12,300
And this is a relationship is what tells us that we will need to use inheritance.

16
00:01:13,260 --> 00:01:13,610
All right.

17
00:01:13,620 --> 00:01:20,490
So inheritance is going to be a way of kind of organizing our programs and having certain characteristics

18
00:01:20,490 --> 00:01:24,990
of a car be able to be used across these subtypes of cars.

19
00:01:26,130 --> 00:01:27,240
So let's take a closer look.

20
00:01:27,900 --> 00:01:30,120
So here we see our car class, right?

21
00:01:30,140 --> 00:01:35,220
So just think of this blog right here as what we've created so far with the car class.

22
00:01:36,300 --> 00:01:40,470
Then you see arrows going down here to truck sedan and SUV.

23
00:01:41,310 --> 00:01:43,130
These are also classes.

24
00:01:43,140 --> 00:01:47,400
So truck is a class sedan is a class, an SUV is a class.

25
00:01:48,090 --> 00:01:51,240
The car class is what we will refer to as a base class.

26
00:01:51,270 --> 00:01:54,360
It's kind of the overarching king of all of these.

27
00:01:55,890 --> 00:01:59,760
If we go down here, these are referred to as the derived classes.

28
00:01:59,760 --> 00:02:04,260
So truck derived from car sedan drives from car SUV, rational car.

29
00:02:04,790 --> 00:02:12,330
When we say they're driving the same car, we really mean that they are inheriting some traits of a

30
00:02:12,330 --> 00:02:13,020
car, right?

31
00:02:13,620 --> 00:02:17,880
These three things here share some common traits, right?

32
00:02:18,360 --> 00:02:18,700
Sure.

33
00:02:18,780 --> 00:02:27,420
Trucks, sedan and SUV, they all require some type of fuel, whether that be like electric or diesel

34
00:02:27,420 --> 00:02:35,160
or, you know, just petrol or whatever, you know, normal gas.

35
00:02:36,710 --> 00:02:40,250
They also have wheels, you know, they probably have windows.

36
00:02:41,450 --> 00:02:45,470
They say they're going to share some things right, and those things are traits of a car.

37
00:02:46,040 --> 00:02:47,840
But these are more specific types.

38
00:02:48,380 --> 00:02:55,100
The point is is that they might kind of have, you know, the stuff that they share could be captured

39
00:02:55,100 --> 00:03:01,070
in a base class here, whereas each separate drive class might have some additional specifics, right?

40
00:03:01,070 --> 00:03:07,880
Like a truck might have, like a truck bed, a sedan is small, probably gets good gas mileage and SUV

41
00:03:07,940 --> 00:03:09,230
sports utility vehicle.

42
00:03:09,230 --> 00:03:12,050
It can fit more people into things in it, but it's not a truck.

43
00:03:12,740 --> 00:03:21,110
So, yeah, you can see that the relationship between the three is that they're all cars, and that's

44
00:03:21,110 --> 00:03:21,680
the main point.

45
00:03:23,810 --> 00:03:31,700
So we're going to use something called unified modeling language, or UML for short as a way of visually

46
00:03:31,700 --> 00:03:34,630
showing our relationships between these classes.

47
00:03:34,640 --> 00:03:40,040
And it's not only going to be the relationships, but it's also going to lay out our classes as far

48
00:03:40,040 --> 00:03:43,910
as the information that's stored inside those classes.

49
00:03:44,570 --> 00:03:47,840
So your e-mail can help you with designing your code structure.

50
00:03:48,200 --> 00:03:55,310
Sometimes it's nice to lay everything out visually first before you start writing code or kind of jumping

51
00:03:55,310 --> 00:03:57,650
back and forth in between writing some code.

52
00:03:58,040 --> 00:04:00,350
Adding to a visualization or a model.

53
00:04:00,680 --> 00:04:01,910
And then going back to your code.

54
00:04:04,600 --> 00:04:09,140
So let's take a look at this, so here we have our car class.

55
00:04:09,460 --> 00:04:12,400
Our basic car class that we've already been working with, kind of.

56
00:04:13,420 --> 00:04:15,310
Here are the data members.

57
00:04:15,310 --> 00:04:18,490
So this is a UML style diagram here.

58
00:04:18,490 --> 00:04:20,140
It only has one class.

59
00:04:20,440 --> 00:04:22,660
But here's the class name.

60
00:04:23,080 --> 00:04:28,780
This is right here in between these lines is reserved for the data members.

61
00:04:29,800 --> 00:04:34,900
The dating rumours here you see fuel paint, color and mileage, so these are variables.

62
00:04:36,310 --> 00:04:42,070
Another thing is these minus signs here with the minus signs mean is that these are private data members.

63
00:04:42,070 --> 00:04:49,240
So if we are going to create our class, these variables will go in the private section of our class

64
00:04:49,240 --> 00:04:53,740
definition and our header file moving down to here.

65
00:04:53,770 --> 00:04:56,110
These are our member functions.

66
00:04:56,740 --> 00:04:58,960
So here is the data member area.

67
00:04:59,020 --> 00:05:00,510
These are the member functions.

68
00:05:00,520 --> 00:05:02,770
This is a member function area below this line here.

69
00:05:04,540 --> 00:05:08,620
And the plus sign, like you might have guessed, is public instead of private.

70
00:05:08,620 --> 00:05:13,030
So minus this minus means private and plus means public.

71
00:05:13,600 --> 00:05:18,370
So each of these minus signs go with each of these variables, and they mean that each one of them is

72
00:05:18,370 --> 00:05:18,880
private.

73
00:05:19,300 --> 00:05:23,230
The plus signs here mean that these are public member functions.

74
00:05:26,230 --> 00:05:33,060
So what I want you to do kind of is an easy challenge is to implement the car class, as shown in the

75
00:05:33,130 --> 00:05:34,870
email in the previous slide.

76
00:05:35,260 --> 00:05:40,060
And don't worry, I will jump back up to that and you can either write down or screenshot it or just

77
00:05:40,060 --> 00:05:40,900
take a look at it.

78
00:05:41,560 --> 00:05:42,970
You can pass that video on it.

79
00:05:44,100 --> 00:05:44,850
Whatever you like.

80
00:05:45,690 --> 00:05:52,200
So will then make you a male model with the other classes using inheritance and implement that as well.

81
00:05:52,210 --> 00:06:01,320
But what I want you to do right now is just take a look at this right here and I want you to then implement

82
00:06:01,320 --> 00:06:02,520
this in code.

83
00:06:02,520 --> 00:06:04,080
So just make a class.

84
00:06:05,250 --> 00:06:09,720
You should make a header file and you should make a copy file.

85
00:06:09,780 --> 00:06:12,810
And you don't need to worry about like a main file for a client code.

86
00:06:12,810 --> 00:06:17,910
Yet we will be doing that a little bit later, but what you should do is definitely make a header file

87
00:06:17,910 --> 00:06:24,300
that has a public and private section and defines these variables and member functions, as well as

88
00:06:24,300 --> 00:06:32,970
a CPP implementation file that has skeletons for these right here and also should have a constructor.

89
00:06:33,510 --> 00:06:36,480
So make sure that you make a constructor as well.

90
00:06:38,450 --> 00:06:38,860
All right.

91
00:06:38,960 --> 00:06:44,140
So you can go ahead and pass the video and do that, and then I will head over to the editor and we'll

92
00:06:44,300 --> 00:06:44,900
get started.

93
00:06:47,580 --> 00:06:54,390
OK, so I am going to exit out of here, and I already have a new project here and sea lion, but what

94
00:06:54,390 --> 00:07:02,250
I'm going to do is right click here and I'm actually going to say new C++ class instead of separately

95
00:07:02,250 --> 00:07:03,500
doing header and source.

96
00:07:03,510 --> 00:07:05,220
I can just click class.

97
00:07:06,530 --> 00:07:09,350
And it's going to make CP and header file for me.

98
00:07:09,710 --> 00:07:11,660
So what I'm going to call this is car.

99
00:07:13,590 --> 00:07:15,780
All right, so I'm going to go ahead and click, OK.

100
00:07:18,880 --> 00:07:24,040
Of course, though, it would something I love about Sea Lion, you know, it already defined by macro

101
00:07:24,040 --> 00:07:25,180
guys here and everything.

102
00:07:25,720 --> 00:07:28,210
And here we have our head and RCP.

103
00:07:30,080 --> 00:07:32,630
So what do we need to implement?

104
00:07:32,660 --> 00:07:40,490
Let's go back to our dining diagram, so we feel painkiller and mileage as private data members and

105
00:07:40,490 --> 00:07:42,530
these as public, these methods.

106
00:07:43,220 --> 00:07:48,650
So I'm going to go ahead and say public and I will say private.

107
00:07:50,210 --> 00:07:53,480
So my private is going to be a.

108
00:07:54,960 --> 00:08:00,960
We have fuel painkiller mileage, so fuel is most likely going to be in gallons, which I'll put as

109
00:08:00,960 --> 00:08:04,470
an integer, so I'll say and feel.

110
00:08:07,190 --> 00:08:09,950
The painkiller will most likely be a string.

111
00:08:11,360 --> 00:08:15,680
So I'm actually going to say a sturdy string

112
00:08:18,810 --> 00:08:25,060
painkiller, and I should probably put something in here like include ice cream or string.

113
00:08:27,450 --> 00:08:28,890
So we can have access to that.

114
00:08:29,700 --> 00:08:35,790
So then what I want to do is let's see mileage, so I'm also going to have, I think, going to have

115
00:08:35,790 --> 00:08:37,170
mileage as a float.

116
00:08:37,950 --> 00:08:40,290
So I will say float mileage.

117
00:08:42,910 --> 00:08:48,520
Cool, and I like to kind of like name my dad remembers with Underscores before then just as a naming

118
00:08:48,940 --> 00:08:54,280
convention, and kind of this can actually be like turned into camel case like, say, pain killer like

119
00:08:54,280 --> 00:08:54,550
that.

120
00:08:56,900 --> 00:09:01,850
So let's look at the methods we have show fuels that feel get odometer set paint.

121
00:09:02,520 --> 00:09:05,210
So let's go ahead and start doing those as public methods.

122
00:09:06,170 --> 00:09:12,860
So I'm going to have show fuel will probably be a void.

123
00:09:13,640 --> 00:09:14,330
Let's see.

124
00:09:14,960 --> 00:09:18,860
Or no show fuel will probably be an integer because it's going to return.

125
00:09:19,490 --> 00:09:22,100
So let's go ahead and return.

126
00:09:22,310 --> 00:09:24,350
We'll put an end because it a return the fuel.

127
00:09:24,350 --> 00:09:32,030
It will basically be like get fuel, but get fuel sounds like you're actually getting gas and putting

128
00:09:32,030 --> 00:09:34,900
gas when we really just want to return the what the fuel is.

129
00:09:34,900 --> 00:09:36,500
So that's why I'm playing a show field.

130
00:09:37,580 --> 00:09:41,090
So if they show fuel returns and aren't.

131
00:09:44,530 --> 00:09:50,500
Set fuel, so set fuel will take an integer and it will be void.

132
00:09:51,190 --> 00:09:56,940
So say said fuel and this will take an integer fuel.

133
00:09:58,810 --> 00:10:00,610
Then we have get odometer.

134
00:10:01,060 --> 00:10:06,890
So let's go ahead and do that, so get odometer should return the mileage, so that will be afloat,

135
00:10:06,940 --> 00:10:07,270
right?

136
00:10:07,780 --> 00:10:17,140
So I'll say get old down there, then we have set paint and get pain.

137
00:10:18,100 --> 00:10:19,840
Now let's actually get paint.

138
00:10:20,440 --> 00:10:22,440
So let's go ahead and do that.

139
00:10:22,450 --> 00:10:28,210
So we'll say set paint will be void, set paint and this will be a string.

140
00:10:31,320 --> 00:10:41,910
Color and then we'll have to get paint, will return a string and say, get paint like that.

141
00:10:44,120 --> 00:10:45,110
OK, OK, cool.

142
00:10:45,120 --> 00:10:49,080
So I think that handles everything here for the car class.

143
00:10:49,410 --> 00:10:54,690
So let's go ahead, and since I'm a sea lion, I can actually just choose to.

144
00:10:55,970 --> 00:11:01,880
Make create definitions for these so I can go here and I can't say generate definition for show fuel

145
00:11:02,540 --> 00:11:03,880
that'll generate that here.

146
00:11:04,790 --> 00:11:07,760
I was saying, I just can't do that for each one of these.

147
00:11:07,970 --> 00:11:11,270
So generate definition for set fuel.

148
00:11:13,990 --> 00:11:15,880
Any definition for ODOMETER?

149
00:11:16,720 --> 00:11:21,310
So this is a really nice thing about sea and that I like, and so you can just click and it'll generate

150
00:11:21,310 --> 00:11:22,420
the definition for you.

151
00:11:27,480 --> 00:11:27,810
All right.

152
00:11:27,840 --> 00:11:33,390
And you can also generate it in place, you see, so you can actually put implementations here in the

153
00:11:33,390 --> 00:11:34,180
header as well.

154
00:11:34,200 --> 00:11:36,180
But we're going to separate them out into the CBP.

155
00:11:38,000 --> 00:11:38,690
All right, cool.

156
00:11:38,720 --> 00:11:41,760
So another thing that we needed was our constructive, though, right?

157
00:11:41,810 --> 00:11:49,340
So I'm actually going to say car as a constructor and then we're going to set these two default values.

158
00:11:49,610 --> 00:11:53,320
So let's go ahead and head over here.

159
00:11:53,330 --> 00:11:56,870
So let's osteria definition for this to.

160
00:11:58,450 --> 00:11:58,870
Cool.

161
00:11:59,110 --> 00:12:02,250
So I actually want this to be of top, so I'm going to.

162
00:12:04,650 --> 00:12:10,020
See, I keep it small for now, because I'm going to just grow up here and do that, but then I'll see

163
00:12:10,020 --> 00:12:11,100
you in in just a second.

164
00:12:11,790 --> 00:12:12,150
All right.

165
00:12:16,130 --> 00:12:22,520
So let's go ahead and set our data members, so we want to and let's see where painkiller fuel and mileage,

166
00:12:22,520 --> 00:12:24,640
and he said fuel to zero.

167
00:12:24,650 --> 00:12:26,660
So let's just say we start out with zero.

168
00:12:26,900 --> 00:12:32,030
I know before I think we started out with fuel or something else, but let's just pretend that when

169
00:12:32,030 --> 00:12:37,070
you have the basic car, it just comes with zero fuel.

170
00:12:37,070 --> 00:12:42,080
So maybe like there's some initial gas like feeling that we have to do right away.

171
00:12:42,080 --> 00:12:43,780
So paint color.

172
00:12:43,820 --> 00:12:50,750
We'll just say, uh, well, when it started out as just say white.

173
00:12:51,110 --> 00:12:52,250
It just starts this white.

174
00:12:53,390 --> 00:12:57,260
And then we have our mileage.

175
00:12:58,100 --> 00:13:01,250
So let's just say mileage starts at zero point zero, right?

176
00:13:01,520 --> 00:13:01,970
So what?

177
00:13:02,030 --> 00:13:03,110
The car was no miles.

178
00:13:04,100 --> 00:13:05,330
So there's I command structure.

179
00:13:07,280 --> 00:13:11,930
All right, so show feel this will just return the fuel.

180
00:13:13,370 --> 00:13:18,050
So let's just add fuel there, their set fuel.

181
00:13:18,230 --> 00:13:24,800
So this will just be fuel equals fuel underscore fuel equals fuel.

182
00:13:25,670 --> 00:13:30,590
So get odometer will return mileage.

183
00:13:32,390 --> 00:13:37,220
And then set paint will just say paint color equals color.

184
00:13:39,900 --> 00:13:46,590
And so get paint will just return paint color as well.

185
00:13:48,420 --> 00:13:53,850
OK, so another thing just to point out, you know, if you haven't noticed this already is that a big

186
00:13:53,850 --> 00:13:59,760
part of the object oriented design is having accessories and mutations or setters and getters.

187
00:13:59,760 --> 00:14:01,140
You can refer to them either or.

188
00:14:01,830 --> 00:14:02,310
So.

189
00:14:03,770 --> 00:14:11,420
The senators are basically mutations and the Kennedys are accessories, so this is a getter.

190
00:14:11,750 --> 00:14:16,700
So what it does is it just returns on to the private data members to you.

191
00:14:17,180 --> 00:14:19,820
This is an important concept of encapsulation.

192
00:14:19,820 --> 00:14:23,540
So I might have said this already, but I just kind of want to reiterate if I haven't.

193
00:14:24,140 --> 00:14:31,730
So encapsulation is an important concept that has to do with us kind of protecting our data members

194
00:14:31,730 --> 00:14:38,870
and only exposing things to the user of our library or just our code.

195
00:14:39,020 --> 00:14:46,640
Whoever is instantiating our classes, we want to kind of force a certain behavior to for interaction

196
00:14:46,640 --> 00:14:47,480
with our data.

197
00:14:47,510 --> 00:14:47,810
Right.

198
00:14:48,470 --> 00:14:56,510
So we expose kind of this interface for people to access our data, and that's through setters and getters.

199
00:14:57,050 --> 00:15:00,620
So this right here is a ganar function.

200
00:15:01,190 --> 00:15:05,420
I wouldn't call it get fuel, but I think she'll feel sounds more appropriate.

201
00:15:06,230 --> 00:15:09,980
It's just returning a value and you notice these setters.

202
00:15:09,980 --> 00:15:16,940
What they do is they instead of returning the value, they set a value so the user passes in a value

203
00:15:16,940 --> 00:15:20,360
and the data member of our class gets set to that value.

204
00:15:22,050 --> 00:15:25,460
You know that like this is just a series of setters and getters.

205
00:15:25,460 --> 00:15:30,650
It's basically like you get the full set, the fuel, get the odometer.

206
00:15:31,550 --> 00:15:32,830
We haven't done.

207
00:15:32,840 --> 00:15:33,350
Let's see.

208
00:15:35,570 --> 00:15:37,310
The get odometer.

209
00:15:37,340 --> 00:15:39,710
We don't set the odometer, so that doesn't have it.

210
00:15:40,220 --> 00:15:45,530
This is just a get road down downer, but we have, you know, get fuel, set fuel, get the odometer.

211
00:15:45,860 --> 00:15:48,500
We have set paint and get paint.

212
00:15:49,100 --> 00:15:54,350
So these are all like series of setters and getters, which is an important concept for object oriented

213
00:15:54,350 --> 00:15:59,150
programming and definitely a good technique to use when you're programming.

214
00:16:02,010 --> 00:16:07,710
So I think that kind of does it for setting up our car class, you know, keeping it pretty basic.

215
00:16:07,710 --> 00:16:11,640
This already came with a client while I said you didn't have to make it, but when I created my project,

216
00:16:11,640 --> 00:16:14,510
it just put this made seep in here for me.

217
00:16:14,520 --> 00:16:17,130
So if you want to add that you can, but you don't have to right now.

218
00:16:18,660 --> 00:16:21,600
So let's head back over here to the slides.

219
00:16:24,190 --> 00:16:31,270
So we already had and went ahead and implemented that, so now we're going to talk about inheritance

220
00:16:31,270 --> 00:16:35,470
and we're going to use you and Mel to show what inheritance is doing.

221
00:16:35,480 --> 00:16:41,920
So before I show the inheritance relationship between these classes in, you know, how you're supposed

222
00:16:41,920 --> 00:16:42,430
to show it.

223
00:16:43,150 --> 00:16:45,150
I'm going to go over some of these other classes here.

224
00:16:45,160 --> 00:16:46,830
So here we have our base class, right?

225
00:16:46,840 --> 00:16:48,640
We just implemented this in code.

226
00:16:49,270 --> 00:16:54,670
So let's think about what the other classes would look like the derived classes of car.

227
00:16:55,720 --> 00:16:59,980
So a truck and these you can put kind of whatever you like in here.

228
00:16:59,980 --> 00:17:06,550
But I'm just I just put this stuff here because I thought it was simple and made sense, doing kind

229
00:17:06,550 --> 00:17:11,820
of segregated stuff and having some data members that have to do with the specific type of car.

230
00:17:11,830 --> 00:17:18,700
So trying to keep it simple, just so we can focus more on the concept of inheritance and having subclasses

231
00:17:18,700 --> 00:17:24,550
drive classes rather than getting into some details of some implementation of a class.

232
00:17:26,890 --> 00:17:33,280
So let's look at trucks, so truck has two private data members.

233
00:17:33,820 --> 00:17:34,750
Bed length.

234
00:17:35,020 --> 00:17:41,040
So how long is the bed of the truck in the back to store stuff and then a is full cab?

235
00:17:41,050 --> 00:17:42,490
So this sounds like a Boolean, right?

236
00:17:42,490 --> 00:17:45,790
Like it is full cab is either a yes or no thing.

237
00:17:46,690 --> 00:17:50,380
So we have this private Boolean as well that tells you whether it's full cab.

238
00:17:50,950 --> 00:17:57,670
Our methods here set bed length, get bed length set is full cab and get it full cab.

239
00:17:59,600 --> 00:18:05,720
Our sedan here, we have private members as the number of doors, so as the two door or four door or

240
00:18:05,720 --> 00:18:11,390
something like that we have is compact to just know if it's like a small compact car and the bullying

241
00:18:11,390 --> 00:18:11,840
as well.

242
00:18:12,230 --> 00:18:13,580
And then we've got setting on doors.

243
00:18:13,610 --> 00:18:16,670
Getting some doors set is compact and get is compact.

244
00:18:17,840 --> 00:18:19,580
So pretty simple, you know?

245
00:18:22,370 --> 00:18:30,230
Methods and stuff here, you know, we're not going to crazy SUV, has no seats or is all wheel drive,

246
00:18:31,070 --> 00:18:39,050
so you notice that we have this pattern of like integers and billions for our data members and then

247
00:18:39,050 --> 00:18:40,670
we have setters and getters for those.

248
00:18:41,420 --> 00:18:46,160
So we have seats, get seats and set is all wheel drive and get this all wheel drive.

249
00:18:47,930 --> 00:18:48,410
Cool.

250
00:18:49,130 --> 00:18:56,030
So if you're looking at this and you smell, it would be represented with something like this.

251
00:18:56,210 --> 00:18:56,690
So.

252
00:18:58,240 --> 00:19:00,590
There will be an arrow.

253
00:19:00,610 --> 00:19:05,080
It has kind of an empty arrowhead coming from these free classes.

254
00:19:06,130 --> 00:19:08,930
And the empty arrowhead means inheritance.

255
00:19:09,710 --> 00:19:19,200
So what it means is that these three classes here are kind of extending the car class.

256
00:19:20,420 --> 00:19:25,310
So what that means is that they are inheriting if you're thinking about it going down this way, when

257
00:19:25,310 --> 00:19:30,530
we had arrows this way, it's like truck is inheriting from car sedans, inheriting from car SUVs inherited

258
00:19:30,530 --> 00:19:31,040
from car.

259
00:19:31,850 --> 00:19:37,970
When you look at it from this way you, you're basically seen it as an extension.

260
00:19:37,970 --> 00:19:39,680
So you're like truck extends.

261
00:19:39,680 --> 00:19:46,640
This class sedan extends this class SUV extends this class, and that just means that each one of these

262
00:19:46,640 --> 00:19:52,970
classes will be able to have access to the public data member.

263
00:19:52,980 --> 00:19:56,950
Sorry, the public information of the car class.

264
00:19:56,960 --> 00:20:02,090
So these are private data members, so we will not be able to refer directly to these.

265
00:20:02,450 --> 00:20:10,070
But what we will be able to use is when we make a sedan object, for example, we will be able to call

266
00:20:10,130 --> 00:20:14,360
these public methods on a sedan object.

267
00:20:14,630 --> 00:20:19,970
It doesn't always have to be like the inherited class being extending it in a public way.

268
00:20:22,890 --> 00:20:25,620
We actually can do it.

269
00:20:26,490 --> 00:20:28,410
I should probably put a tee there for the paint.

270
00:20:28,800 --> 00:20:33,780
We actually can set that up differently as well, but I will get into that later.

271
00:20:33,870 --> 00:20:41,070
But the point is is that we will be able to today when we're implementing these derived classes, we

272
00:20:41,070 --> 00:20:43,920
will be able to make an object of each one of them.

273
00:20:44,220 --> 00:20:50,470
And if we want to, we could do track dot, get paint, truck dot set feel.

274
00:20:51,060 --> 00:20:55,650
Of course, in addition to trucks, get bed length and stuff like that.

275
00:20:56,400 --> 00:20:58,980
So it's inherent in the functionality.

276
00:20:59,010 --> 00:21:04,050
Each one of these is inherent in the functionality of this car class, as well as some of the data,

277
00:21:04,050 --> 00:21:04,710
potentially.

278
00:21:04,710 --> 00:21:10,020
But these are private and we're not going to be using those when we're doing this public kind of inheritance

279
00:21:10,260 --> 00:21:11,070
in this lesson.

280
00:21:12,540 --> 00:21:19,190
So that is the point that they are all cars in, so you can access these methods that have to do with

281
00:21:19,200 --> 00:21:19,600
a car.

282
00:21:19,620 --> 00:21:25,230
I mean, a sedan is a car, it's going to have paint and it's going to have an odometer, right?

283
00:21:25,260 --> 00:21:26,400
Same with an SUV.

284
00:21:26,400 --> 00:21:29,970
They're all going to share these methods up here.

285
00:21:29,970 --> 00:21:35,010
So SUV will have access to this sedan, will have access to this truck, will have access to this.

286
00:21:35,340 --> 00:21:42,960
But then you notice that each one of them has their own methods and data that is specific to the subtype

287
00:21:42,960 --> 00:21:43,650
of car.

288
00:21:43,680 --> 00:21:44,070
Right.

289
00:21:44,790 --> 00:21:46,260
Truck has bed length.

290
00:21:46,260 --> 00:21:47,580
Sedan doesn't have that length.

291
00:21:47,580 --> 00:21:51,360
It's not going to have a bed, an SUV, not going to have a bed, either.

292
00:21:51,360 --> 00:21:58,320
So that's why, you know, they each have their own stuff in here as well as sharing stuff.

293
00:22:00,840 --> 00:22:03,390
All right, so let's go ahead and implement it.

294
00:22:03,400 --> 00:22:06,870
So we're going to head over to the editor and we're going to try and implement when we described in

295
00:22:06,870 --> 00:22:07,800
this new normal model.

296
00:22:07,800 --> 00:22:10,590
So if you need to, you can always go back and parse it right here.

297
00:22:10,680 --> 00:22:14,490
Take a look at this new email so it can help you implement it.

298
00:22:14,850 --> 00:22:16,680
But you can just follow along, too.

299
00:22:16,710 --> 00:22:17,790
Because I'm going to go over it.

300
00:22:20,260 --> 00:22:25,000
All right, and we're going over some of the syntax that's needed to use inheritance as well.

301
00:22:29,320 --> 00:22:35,020
OK, so we're going to go ahead and make some more classes, why don't we go ahead and do that first?

302
00:22:35,020 --> 00:22:37,060
So we want to make our draft classes.

303
00:22:37,320 --> 00:22:39,250
What I'm going to do is just go over here.

304
00:22:39,790 --> 00:22:47,080
I'm going to right click on my inheritance folder and I'm going to say a new C++ class.

305
00:22:49,600 --> 00:22:53,260
So what I'm going to do is call this one truck.

306
00:22:58,460 --> 00:22:58,910
All right.

307
00:22:59,210 --> 00:22:59,720
So.

308
00:23:00,930 --> 00:23:04,110
Let's go ahead and get stuff started and we'll make a

309
00:23:07,050 --> 00:23:09,030
public and private.

310
00:23:13,500 --> 00:23:25,140
But one thing that we want to do up here is I'm going to include the car h class and then what we're

311
00:23:25,140 --> 00:23:36,240
going to do if we're actually going to put a call in here and then we're going to say public and car,

312
00:23:38,040 --> 00:23:39,630
and now I want to put public car.

313
00:23:39,630 --> 00:23:41,310
You notice that this pops up right here.

314
00:23:41,580 --> 00:23:43,890
It says, go to super type.

315
00:23:45,120 --> 00:23:53,250
So what this is is this is the syntax for declaring that the truck class is going to inherit.

316
00:23:54,500 --> 00:24:03,380
Publicly, as a access specify, this is like an access pacifier for the class, the super class, which

317
00:24:03,380 --> 00:24:04,060
is car.

318
00:24:04,070 --> 00:24:09,560
So this syntax here is saying that the class truck, I want it to inherit from the car class.

319
00:24:10,190 --> 00:24:13,070
And when it says go to super type.

320
00:24:13,820 --> 00:24:22,010
Another thing that you can say is that car is a super class four truck sedan, an SUV.

321
00:24:23,060 --> 00:24:25,700
So it's a super class, it's a base class.

322
00:24:25,700 --> 00:24:27,980
You just think of it as like the ultimate class.

323
00:24:28,370 --> 00:24:32,540
But people quite often refer to it as the base class or super class.

324
00:24:34,180 --> 00:24:39,100
And this is the syntax to inherit from that super class or base class.

325
00:24:39,610 --> 00:24:45,160
You put a colon, you put the access, specify a type which we're just going to be doing in public right

326
00:24:45,160 --> 00:24:45,550
now.

327
00:24:46,450 --> 00:24:48,670
And then you put the name of the class.

328
00:24:50,260 --> 00:24:57,670
OK, so let's go ahead and start implementing some data and like data members and methods.

329
00:24:57,670 --> 00:25:01,930
So if I go back here, I think I can.

330
00:25:03,750 --> 00:25:10,230
Yeah, we have the Sudan truck bed length and is full cab.

331
00:25:12,450 --> 00:25:12,870
Cool.

332
00:25:13,500 --> 00:25:21,990
So we'll stay in bed length and below is the full cab.

333
00:25:24,060 --> 00:25:28,020
Now, let's check this out, so we have the.

334
00:25:29,920 --> 00:25:30,490
Let's see.

335
00:25:30,730 --> 00:25:31,760
Set bed length.

336
00:25:31,780 --> 00:25:32,860
Get bed length.

337
00:25:34,230 --> 00:25:47,050
Public methods, so we will say and set bed length and this will just be in length and then we will

338
00:25:47,050 --> 00:25:49,480
avoid or actually leave my bed.

339
00:25:49,530 --> 00:25:58,230
This is vice versa, Boyd and and get fabulous in this or just return the bed length.

340
00:25:59,190 --> 00:25:59,960
What was the other one?

341
00:25:59,970 --> 00:26:02,910
So we have yes, it is full of gas vocab.

342
00:26:02,910 --> 00:26:05,100
So we'll have this.

343
00:26:06,900 --> 00:26:09,000
Let's see, Boyd said.

344
00:26:09,060 --> 00:26:13,380
It is for CAB.

345
00:26:14,610 --> 00:26:15,570
So this will be.

346
00:26:17,790 --> 00:26:21,510
And I'll just call this cab or something like that.

347
00:26:21,990 --> 00:26:30,780
So then we'll have a pool as returned by get is for cab.

348
00:26:33,660 --> 00:26:40,500
So we could also change these, we could just say, you know, you could just say like.

349
00:26:41,930 --> 00:26:49,970
Uh, you know, is full cab, I can kind of show you that in a bit, but there is a way that we can

350
00:26:49,970 --> 00:26:52,250
just have it be kind of all in one.

351
00:26:52,970 --> 00:26:59,960
So I might go back over this and kind of show you how you can have setters and getters combined in one.

352
00:27:01,570 --> 00:27:03,550
But for right now, we're going to separate them.

353
00:27:03,910 --> 00:27:06,100
OK, so these are all of our methods here.

354
00:27:06,630 --> 00:27:11,200
So actually, we probably want to put a constructor, right?

355
00:27:12,010 --> 00:27:13,420
So we'll do a constructor.

356
00:27:13,990 --> 00:27:18,310
So go ahead and just say generate definition for that.

357
00:27:19,390 --> 00:27:21,520
And then we will.

358
00:27:24,380 --> 00:27:26,000
Generate definition for this.

359
00:27:28,280 --> 00:27:28,650
Cool.

360
00:27:32,870 --> 00:27:33,350
Or.

361
00:27:35,260 --> 00:27:38,320
You know, you can kind of do it two ways you can just like, hover over it.

362
00:27:40,110 --> 00:27:43,170
And then click on it, or you can actually click on it and then do the light bulb.

363
00:27:45,600 --> 00:27:48,290
All right, so we should say our data members here, right?

364
00:27:48,600 --> 00:27:52,860
So we have, let's just say, bed length starts out.

365
00:27:53,280 --> 00:27:55,260
I don't know what the default bed length would be.

366
00:27:55,290 --> 00:28:03,660
We could just say like six, four six feet or something like that and then is full have let's just say

367
00:28:03,660 --> 00:28:07,920
that's kind of an upgrade should be like initially set to false.

368
00:28:09,360 --> 00:28:18,360
All right, so this will just be setting the bad links, so the safe bed length equals its length and

369
00:28:18,360 --> 00:28:22,380
then get bed length is just going to return badly to us.

370
00:28:24,430 --> 00:28:28,980
City's full cab, so that's just is full cab equals cab.

371
00:28:32,100 --> 00:28:38,460
And then get is full cab and just say the turn is full cap, so pretty simple here we just have our

372
00:28:38,460 --> 00:28:39,330
setters and getters.

373
00:28:40,020 --> 00:28:42,300
And that should be everything for our truck class.

374
00:28:43,820 --> 00:28:45,110
So, yeah.

375
00:28:46,150 --> 00:28:47,530
I think we're good to go there.

376
00:28:48,780 --> 00:28:54,720
So I'm actually going to I'm just going to say this all right now, but I'm going to get out of.

377
00:28:55,860 --> 00:28:57,780
These so we can kind of make some more.

378
00:28:59,420 --> 00:29:03,440
Some more room when we do the other ones, so let's go ahead and make another class, so I'm going to

379
00:29:03,440 --> 00:29:05,240
say new C++ class.

380
00:29:05,900 --> 00:29:07,490
This one is going to be sedan

381
00:29:10,490 --> 00:29:17,030
and I would kind of encourage you at this point actually to maybe pause the video and see if you can

382
00:29:17,030 --> 00:29:23,910
actually implement the sedan class and the SUV class.

383
00:29:23,930 --> 00:29:31,280
This would be great practice and would help you learn better than just watching me go through the motions

384
00:29:31,280 --> 00:29:32,060
of doing this.

385
00:29:32,450 --> 00:29:34,310
You've already seen how we did it for truck.

386
00:29:34,790 --> 00:29:36,220
It's going to be very similar.

387
00:29:36,230 --> 00:29:41,390
You can reference the UML that we had to be able to create those classes.

388
00:29:41,540 --> 00:29:46,670
So if you can go ahead and try to pause the video and finish the other two before I walk through it.

389
00:29:47,360 --> 00:29:47,630
All right.

390
00:29:47,630 --> 00:29:49,130
Well, I'll go ahead and go right, though.

391
00:29:51,790 --> 00:29:59,320
So I'm going to go ahead and include the card each year, and then what we're going to do is our inheritance

392
00:29:59,320 --> 00:29:59,680
rights.

393
00:29:59,680 --> 00:30:04,420
I'm going day public car and you see that superclass thing pop up.

394
00:30:04,450 --> 00:30:07,540
So if I click this, it'll take us to car, so I click there.

395
00:30:07,540 --> 00:30:10,510
It takes us to car that age and then you click here.

396
00:30:11,290 --> 00:30:12,580
It says, Go to subclass.

397
00:30:12,850 --> 00:30:15,310
I click here and it gives us sedan or truck.

398
00:30:15,490 --> 00:30:15,850
All right.

399
00:30:16,370 --> 00:30:18,790
So nice way to navigate around here.

400
00:30:18,790 --> 00:30:20,580
So let's go back to sedan age.

401
00:30:22,570 --> 00:30:27,640
So I'm going to go over here and I'm going to say public and then I'm going to say private.

402
00:30:28,030 --> 00:30:32,800
And we should have, let's see, no doors and is compact.

403
00:30:35,450 --> 00:30:42,770
Services and no doors and pull is compact.

404
00:30:44,790 --> 00:30:48,960
So then we should have some methods, right, so we will have.

405
00:30:50,010 --> 00:30:58,760
And you get no doors, no return yet, and then we'll have set no doors.

406
00:30:59,220 --> 00:31:14,550
Well, you hear and doors and then we'll have a ball which will be get is compact and we will have one

407
00:31:14,550 --> 00:31:15,520
which is set.

408
00:31:16,120 --> 00:31:19,940
Yes, contact will.

409
00:31:20,010 --> 00:31:21,450
And we'll just say,

410
00:31:24,810 --> 00:31:28,620
all right, so it's going to hover over these and generate these functions.

411
00:31:34,890 --> 00:31:39,150
And I also need to do a constructor because I haven't done the constructor yet.

412
00:31:40,420 --> 00:31:43,090
So I'll go back here and I'll just say to them,

413
00:31:46,600 --> 00:31:51,070
and let's generate that, but I also like to have this on top.

414
00:31:56,770 --> 00:31:57,310
All right, cool.

415
00:31:57,340 --> 00:32:06,760
So let's go ahead and saying it is compact equals false, and I'll just say no more doors equals two

416
00:32:06,760 --> 00:32:09,430
door, just start out with, but normally it should be.

417
00:32:09,850 --> 00:32:11,410
You can kind of upgrade to four door.

418
00:32:11,410 --> 00:32:11,740
Maybe.

419
00:32:12,610 --> 00:32:13,990
OK, getting them indoors.

420
00:32:13,990 --> 00:32:17,230
So it's returning them doors, setting some doors.

421
00:32:17,560 --> 00:32:27,900
This is just going to be on back and doors, people's doors assuming a little because I've seen.

422
00:32:30,800 --> 00:32:37,820
So return is compact and set as contact will just be campaigning people's confidence.

423
00:32:39,570 --> 00:32:48,870
All right, cool, so we should be good to go now and Thurston TPP, so out of these and then let's

424
00:32:48,870 --> 00:32:53,730
go ahead and do our last one, which will be the sedan or the SUV.

425
00:32:53,890 --> 00:32:54,240
Sorry.

426
00:32:54,240 --> 00:33:01,800
So I will say SUV and press, OK, so.

427
00:33:02,550 --> 00:33:03,900
Oh, cool car.

428
00:33:05,460 --> 00:33:07,320
Let's go ahead and set our inheritance.

429
00:33:11,400 --> 00:33:17,100
All right, so public and private.

430
00:33:18,390 --> 00:33:22,080
And what do we have here, no seats and is all wheel drive.

431
00:33:22,080 --> 00:33:30,030
So and no seats and pool is all wheel drive.

432
00:33:31,950 --> 00:33:32,280
All right.

433
00:33:32,280 --> 00:33:37,620
So first off, this time I'll make my constructor actually.

434
00:33:39,600 --> 00:33:44,190
And then let's go ahead and do an hour

435
00:33:47,280 --> 00:33:54,210
and get no seats or Senate seats,

436
00:33:57,540 --> 00:34:00,540
and then we'll have our floor.

437
00:34:01,500 --> 00:34:04,950
It is all wheel drive

438
00:34:07,830 --> 00:34:08,400
and

439
00:34:11,190 --> 00:34:16,230
all wheel drive rule, and I'll just say,

440
00:34:20,400 --> 00:34:21,000
All right, cool.

441
00:34:21,030 --> 00:34:24,420
So go ahead and generate definitions for these.

442
00:34:39,090 --> 00:34:45,450
OK, cool, so we can go ahead and save our constructor now, so I'll say it's all wheel drive is false

443
00:34:45,460 --> 00:34:52,500
to start out with, but that also seems like kind of an upgrade it and then we'll say no seats equals,

444
00:34:53,730 --> 00:34:56,230
let's just say defaults to five.

445
00:34:56,250 --> 00:35:00,840
But you can have extra rows and stuff, you know, bigger versions of this SUV.

446
00:35:01,680 --> 00:35:11,610
Uh, so we'll just say and turn them seats, nine seats, seat or seats for this one.

447
00:35:13,260 --> 00:35:15,120
Sorry, I didn't come in there.

448
00:35:16,980 --> 00:35:17,490
So

449
00:35:20,370 --> 00:35:25,050
return is all wheel drive and this will just be

450
00:35:29,040 --> 00:35:30,360
is our drive eagle.

451
00:35:30,360 --> 00:35:31,140
So will drive.

452
00:35:32,730 --> 00:35:33,630
All right, cool.

453
00:35:33,990 --> 00:35:37,020
So that should be.

454
00:35:39,110 --> 00:35:39,890
Good to go.

455
00:35:41,420 --> 00:35:47,940
So now, if we go back to some angst out of here, go back to our car class and click on this right

456
00:35:47,960 --> 00:35:52,160
here, go to subclass you notice we have three subclasses that we can go to.

457
00:35:52,940 --> 00:35:54,470
So those are all set up now.

458
00:35:55,790 --> 00:36:01,970
So now what we want to do is go over to our main client file and kind of test this stuff out.

459
00:36:03,730 --> 00:36:09,670
So let's go in here, I'm going to include Zoom in a little bit.

460
00:36:10,870 --> 00:36:22,840
I'm going to include our classes here, so I'm going to include the three, the three subclasses, the

461
00:36:22,840 --> 00:36:24,370
three derived classes.

462
00:36:24,670 --> 00:36:25,480
This is what I want to do.

463
00:36:25,480 --> 00:36:29,320
So I'm going to include trucker h.

464
00:36:30,460 --> 00:36:32,050
I'm going to include.

465
00:36:34,510 --> 00:36:42,100
Sedan age, and I'm going to include the SUV age.

466
00:36:46,410 --> 00:36:55,920
So what I want to do now is make objects of all three of them, so I can just say truck and truck.

467
00:36:58,870 --> 00:37:06,200
A sedan sedan and SUV SUV.

468
00:37:08,860 --> 00:37:16,030
And so let's just call some methods on them, so I can say truck dart.

469
00:37:16,930 --> 00:37:17,710
Uh.

470
00:37:19,220 --> 00:37:24,890
Let's just say, let's see, we have let's check out what we got here, so you notice we have get paint

471
00:37:24,890 --> 00:37:31,440
all these options right here and we can go down with so these get paint and get odometer.

472
00:37:31,460 --> 00:37:34,910
Remember, those are not part of the truck class.

473
00:37:35,660 --> 00:37:38,090
Neither is fuel and so fuel.

474
00:37:38,300 --> 00:37:39,720
So you see that we're all right.

475
00:37:39,740 --> 00:37:44,240
We already have access to these because we inherited from our car class.

476
00:37:45,500 --> 00:37:47,390
So we can call a lot of these.

477
00:37:47,390 --> 00:37:59,690
So if we just say that fuel and let's just say we put 12 gallons in there and then we say truck that

478
00:38:00,980 --> 00:38:07,200
maybe like set paint and just put some horrendous color in here like purple or something like that.

479
00:38:08,390 --> 00:38:10,460
And then what we can do is.

480
00:38:12,640 --> 00:38:19,270
Also, do something maybe like set bed length, and we'll just say the bed length is like eight feet

481
00:38:19,270 --> 00:38:28,810
or something, and then so now what would be kind of cool to do is maybe make some stuff that could

482
00:38:28,810 --> 00:38:30,510
print out our objects, right?

483
00:38:30,520 --> 00:38:32,650
So this would be good practice.

484
00:38:32,660 --> 00:38:37,990
So what I want you to do is actually pause the video if you can.

485
00:38:38,380 --> 00:38:47,110
And for each class, I want you to create overloaded output operators.

486
00:38:47,800 --> 00:38:53,440
So the output like like so we can print it out and see out.

487
00:38:53,440 --> 00:38:59,350
So you know how to do that now since you've seen the overloaded operator VIDEO So why don't you pause

488
00:38:59,350 --> 00:39:00,400
the video and go ahead?

489
00:39:00,400 --> 00:39:06,250
And for each of the derived classes, you should make an overloaded operator?

490
00:39:08,060 --> 00:39:13,100
So let's go ahead and see what that will look like implementing those upgrades.

491
00:39:13,220 --> 00:39:17,390
First, I'm going to need to kind of do the same thing for these other classes.

492
00:39:17,390 --> 00:39:25,580
So I'm going to say Sudan Dot like, let's get the fuel first, actually.

493
00:39:27,430 --> 00:39:35,650
I said fuel 11 or 10, 10 and then we'll do sedan setting doors.

494
00:39:36,970 --> 00:39:39,510
Uh, let's actually set the paint and

495
00:39:42,190 --> 00:39:48,070
the paint, and we'll just say this is blue, and then we'll set the doors to like four.

496
00:39:48,070 --> 00:39:49,210
It'll be a four door.

497
00:39:49,780 --> 00:39:51,730
Let's do the same with the SUV.

498
00:39:51,970 --> 00:39:57,100
We'll go ahead and set your first or say that this is like 11.

499
00:39:57,730 --> 00:40:04,150
We'll do an SUV that set paint and this will just be

500
00:40:07,090 --> 00:40:08,590
our new black.

501
00:40:09,040 --> 00:40:13,300
And then let's do SUV dot.

502
00:40:17,010 --> 00:40:21,560
This is all a drive to.

503
00:40:23,840 --> 00:40:36,320
And I said the number of seats to six feet that said nine seats to eight, so do big sedan, OK?

504
00:40:36,550 --> 00:40:40,820
So we have some stuff set up with our cars now.

505
00:40:41,860 --> 00:40:48,610
So our car types, so let's go ahead and do this overloaded operators and see how that works out.

506
00:40:48,610 --> 00:40:53,710
So I'm going to go over to, let's see, we'll do my truck.

507
00:40:55,270 --> 00:40:56,170
Trucker H.

508
00:40:56,770 --> 00:40:59,350
So irony, like put one right here.

509
00:41:00,490 --> 00:41:05,430
So let's go ahead and go to the truck that CP or we can implement it.

510
00:41:05,440 --> 00:41:13,080
So if you don't remember, it is actually going you the base here.

511
00:41:14,240 --> 00:41:19,600
You don't remember, it's just going to be a friend function and then you're going to do a video stream

512
00:41:19,600 --> 00:41:26,200
and operator and then you're going to put the studio stream passed by reference outs for the stream.

513
00:41:26,200 --> 00:41:31,500
You call it whatever you want, but then you want a constant object by pass by reference as well for

514
00:41:31,510 --> 00:41:32,140
us to print out.

515
00:41:34,910 --> 00:41:41,180
So let's go ahead and start printing out some stuff, so we want to not only print stuff about the truck,

516
00:41:41,810 --> 00:41:47,260
which is like bed length and it's full cab, but we want to print everything about it, right?

517
00:41:47,270 --> 00:41:49,370
And there's some other stuff in car.

518
00:41:51,250 --> 00:41:55,210
That we want to try not to like fuel painkiller mileage, we want to print those out, right?

519
00:41:58,400 --> 00:42:04,940
So let's head back to our truck stop and start cranking now, some would say outs.

520
00:42:06,380 --> 00:42:20,180
And let's just first print a line and just say, you know, truck info, and then we'll go to a new

521
00:42:20,180 --> 00:42:24,260
line and I'll say, Alex, and let's start out with like, let's just start out with like fuel

522
00:42:26,870 --> 00:42:31,400
and then let's go ahead and do T dot fuel.

523
00:42:31,430 --> 00:42:34,670
Oh, wait, where's fuel, though?

524
00:42:35,820 --> 00:42:37,920
It's not on here, huh?

525
00:42:39,390 --> 00:42:45,240
So you might have ran into this error when you were making the outfit streams and been like, Well,

526
00:42:45,240 --> 00:42:48,630
I want to print out all the stuff about it, but.

527
00:42:49,790 --> 00:42:55,910
Why can't I print it out, I can only print out this stuff that has to do with a truck, but there's

528
00:42:55,910 --> 00:42:59,730
more things that have to do with all cars like fuel and odometer mileage.

529
00:43:00,320 --> 00:43:01,130
This stuff, right?

530
00:43:01,550 --> 00:43:02,000
Mileage.

531
00:43:02,000 --> 00:43:03,050
Painkiller fuel.

532
00:43:04,700 --> 00:43:07,250
Why can't I print that out, why don't I have access to that?

533
00:43:08,360 --> 00:43:14,300
Well, I kind of set this up so you would run to that problem and then kind of, you know, I could

534
00:43:14,300 --> 00:43:16,790
solve it right now and tell you what the solution is.

535
00:43:16,790 --> 00:43:21,320
But really, all you have to do is go back to this card age.

536
00:43:21,680 --> 00:43:25,490
You notice that we're what we're doing is inheriting publicly.

537
00:43:26,030 --> 00:43:29,000
So if I go to check that age, we say public car.

538
00:43:29,180 --> 00:43:31,040
So this is the access specification.

539
00:43:32,000 --> 00:43:34,640
We don't necessarily even need to change that, though.

540
00:43:34,880 --> 00:43:38,360
The problem is, is that this is private right here.

541
00:43:38,510 --> 00:43:46,940
But what we could do instead is instead of private, we can just change this to a word called protected.

542
00:43:48,050 --> 00:43:50,300
So protected is like private.

543
00:43:50,630 --> 00:43:51,890
But it doesn't.

544
00:43:51,890 --> 00:43:52,580
It gives.

545
00:43:54,720 --> 00:44:03,750
It doesn't really give access to these items when you instantiating the class that has the protected,

546
00:44:03,750 --> 00:44:12,810
but it will give access to derived classes, so derived classes of car will now have access to these

547
00:44:13,200 --> 00:44:14,700
protected members.

548
00:44:14,910 --> 00:44:15,270
They're not.

549
00:44:15,270 --> 00:44:18,960
They don't have access to private that they have access to protected members.

550
00:44:19,620 --> 00:44:24,120
But you cannot and, you know, protected you still can't like instantiating have access to it.

551
00:44:24,120 --> 00:44:26,790
So go ahead and check this all out.

552
00:44:26,790 --> 00:44:34,290
But now you notice when we go back here to check CPP, I go T dot, and now it gives me a much bigger

553
00:44:34,290 --> 00:44:34,590
list.

554
00:44:34,590 --> 00:44:37,290
Look, I have all of them so I can choose fuel

555
00:44:41,120 --> 00:44:42,240
and put it in line.

556
00:44:42,240 --> 00:44:43,980
And then now we can do the rest, right?

557
00:44:44,580 --> 00:44:50,740
So we'll say color and all.

558
00:44:50,880 --> 00:44:52,440
You know, there's somebody like paint color,

559
00:44:57,240 --> 00:45:03,300
and then I'll say, we have the odometer.

560
00:45:07,400 --> 00:45:08,270
Mileage

561
00:45:13,490 --> 00:45:23,000
and then we have been on at length about that length,

562
00:45:27,470 --> 00:45:35,450
and then we have watched the last one, so is full cab, so has all.

563
00:45:38,720 --> 00:45:39,170
Cam.

564
00:45:53,660 --> 00:45:56,840
All right, cool, so that's pretty much all of our truck info there.

565
00:45:58,600 --> 00:46:05,500
So we got fuel odometer, Melissa, fuel color, odometer and length and has full cab there.

566
00:46:06,220 --> 00:46:10,930
So we're going to pretty much do the same thing for the other classes, so we could just copy paste

567
00:46:10,930 --> 00:46:11,760
a lot of this.

568
00:46:11,770 --> 00:46:17,350
So what I'm going to do is we'll go ahead and get a card each.

569
00:46:17,830 --> 00:46:20,550
We'll do sedan h.

570
00:46:20,560 --> 00:46:22,210
And I'm actually.

571
00:46:24,170 --> 00:46:29,210
Just going to copy this, and I'll put that here.

572
00:46:31,250 --> 00:46:35,440
What we're going to do is change this actually to Sudan.

573
00:46:36,430 --> 00:46:45,310
And I'll call this Earth, and we'll go ahead and generate a definition for this.

574
00:46:49,450 --> 00:46:51,030
This is going to turn out.

575
00:46:51,600 --> 00:46:59,250
And what I'm going to do is I'll just copy this stuff and check that copy and modify it.

576
00:47:01,570 --> 00:47:05,170
So let's head over here and zoom in a bit.

577
00:47:09,220 --> 00:47:09,640
Cool.

578
00:47:09,670 --> 00:47:11,740
So this is actually just going to be as

579
00:47:20,180 --> 00:47:20,430
quick.

580
00:47:21,560 --> 00:47:23,810
So that goes so this bed length stuff.

581
00:47:24,080 --> 00:47:25,440
We're not really going to do that.

582
00:47:25,460 --> 00:47:29,990
This is going to be something else.

583
00:47:30,950 --> 00:47:37,550
So this will be, we'll say, uh, no doors.

584
00:47:46,240 --> 00:47:48,340
So and then this will just be.

585
00:47:51,370 --> 00:47:58,570
I say is home packed and or a that is compact?

586
00:48:01,330 --> 00:48:04,330
Close, so pretty quick fix to get that one going.

587
00:48:04,480 --> 00:48:07,180
So let me go ahead and copy this.

588
00:48:10,420 --> 00:48:15,160
And we will paste this over an SUV now.

589
00:48:16,170 --> 00:48:16,650
So.

590
00:48:22,290 --> 00:48:25,380
And this Naomi sedan will be SUV.

591
00:48:27,680 --> 00:48:29,130
Let's go ahead and.

592
00:48:31,080 --> 00:48:32,700
Generally a definition for this.

593
00:48:41,860 --> 00:48:44,330
I'm going to go here and I'm going to copy this.

594
00:48:44,350 --> 00:48:47,710
We actually want to change this to two Sudan info, right?

595
00:48:48,880 --> 00:48:49,330
And so.

596
00:48:50,650 --> 00:48:55,970
Who are so happy this year.

597
00:48:56,410 --> 00:48:59,890
Pace would be SUV and fell.

598
00:49:02,010 --> 00:49:05,060
And of course, these last two, we want to change.

599
00:49:05,610 --> 00:49:07,050
You don't want no doors.

600
00:49:07,500 --> 00:49:09,920
We want to say like no seats, right?

601
00:49:10,590 --> 00:49:11,790
So no seats.

602
00:49:15,640 --> 00:49:19,390
Seats and then asked is compact is actually going to be asked.

603
00:49:21,910 --> 00:49:26,920
It's all wheel drive, so we'll say it's all wheel drive and then we'll print that out.

604
00:49:27,610 --> 00:49:28,150
OK, cool.

605
00:49:28,150 --> 00:49:33,070
So now we pretty much have everything set up, so now we should be able to print out our objects.

606
00:49:35,790 --> 00:49:41,160
So you also have these accessories as well that will be able to get.

607
00:49:41,310 --> 00:49:44,910
And, you know, we're not using to get it in here, but we can use that in Maine as well.

608
00:49:48,860 --> 00:49:49,250
Cool.

609
00:49:49,280 --> 00:50:00,830
So let's go ahead and print this stuff out, so I'm just going to say, see, see out and we'll just

610
00:50:00,830 --> 00:50:02,690
say truck.

611
00:50:09,940 --> 00:50:11,830
And then we'll say.

612
00:50:14,910 --> 00:50:19,980
So then and I might go added some of those to have line, but

613
00:50:25,320 --> 00:50:26,520
we can print all these out.

614
00:50:27,300 --> 00:50:32,000
So I might go ahead and just add in lines to these.

615
00:50:32,010 --> 00:50:32,850
So.

616
00:50:34,670 --> 00:50:37,760
I only have actually only have it in line after that, so.

617
00:50:42,400 --> 00:50:44,830
Yeah, let's just do.

618
00:50:55,890 --> 00:51:01,650
Copy paste this into a couple of places, because I just want to kind of like an extra line.

619
00:51:10,360 --> 00:51:10,720
All right.

620
00:51:11,110 --> 00:51:17,380
So go ahead and save all of this, and then I'm going to go back to my main and then I'm going to go

621
00:51:17,380 --> 00:51:19,000
ahead and just run this.

622
00:51:19,450 --> 00:51:24,430
And if everything is good to go, we should see our info print out.

623
00:51:30,600 --> 00:51:31,020
Cool.

624
00:51:31,530 --> 00:51:40,200
So we see trucks and an SUV in, so we print this out, truck info says fuel 12 color purple odometer

625
00:51:40,200 --> 00:51:43,620
zero bit length eight has full cab.

626
00:51:45,530 --> 00:51:49,280
That's just print out is zero because it's true or false, like one zero.

627
00:51:50,180 --> 00:51:52,880
So we could set this.

628
00:51:53,060 --> 00:51:57,080
So what if we say that the dot

629
00:52:02,090 --> 00:52:04,940
set is full cab and we'll say true?

630
00:52:06,960 --> 00:52:07,980
So now if I run it.

631
00:52:10,800 --> 00:52:14,340
You notice that we see a one here because it's true.

632
00:52:14,940 --> 00:52:16,740
So like one is true, zero is false.

633
00:52:17,280 --> 00:52:18,540
Sudan Info.

634
00:52:18,790 --> 00:52:21,620
You see it matches up here and then we have our defaults.

635
00:52:25,270 --> 00:52:25,600
Cool.

636
00:52:25,900 --> 00:52:29,980
So, you know, our donors always zero, it might be good to have some function, says Drive.

637
00:52:29,980 --> 00:52:36,100
And it like drives a little bit, makes the miles go up, but you know that could actually happen when

638
00:52:36,100 --> 00:52:38,380
we add some more interfaces and stuff into this.

639
00:52:38,390 --> 00:52:42,520
So I think this was enough to just go over basic inheritance.

640
00:52:43,600 --> 00:52:48,310
I went over a lot of important concepts, and I don't want to stuff too much in here, so it's not too

641
00:52:48,310 --> 00:52:48,940
overwhelming.

642
00:52:48,940 --> 00:52:49,660
And one lesson.

643
00:52:51,000 --> 00:52:56,610
But so what you've seen is how to make a base class, right?

644
00:52:58,650 --> 00:53:04,560
You notice here it says it gives you access to all these subclasses and then we can look at each.

645
00:53:06,340 --> 00:53:12,130
Subclass, for example, as you've been on age and you notice that here, it gives you access to go

646
00:53:12,130 --> 00:53:12,940
to the super type.

647
00:53:13,900 --> 00:53:19,000
And this is how you do the inheritance, you know, a colon and then right for right now we're just

648
00:53:19,000 --> 00:53:25,330
doing a public access to fire and the name of the superclass or the base class, which is car, make

649
00:53:25,330 --> 00:53:26,530
sure to include that as well.

650
00:53:28,180 --> 00:53:34,720
And then you noticed that one of the things that we had to do in the base class for us to have access

651
00:53:34,720 --> 00:53:40,510
to the data members here for our alpha operator are over that it was to change this, to protect it.

652
00:53:42,520 --> 00:53:47,530
All right, cool, so hopefully that was enough for you to get a general idea of inheritance where of

653
00:53:47,530 --> 00:53:53,890
course, going to continue on and kind of of the of this in terms of complexity, and we'll start talking

654
00:53:53,890 --> 00:53:56,590
about some related topics such as polymorphism.

655
00:53:57,430 --> 00:53:57,700
All right.

656
00:53:57,700 --> 00:53:59,320
So with that, I will see you in the next lesson.
