1
00:00:00,340 --> 00:00:02,400
Welcome back to another lesson.

2
00:00:02,910 --> 00:00:08,610
We are continuing on talking about templates, but in this lesson, we're specifically going to talk

3
00:00:08,610 --> 00:00:10,480
about class templates.

4
00:00:10,500 --> 00:00:11,790
And yes, you heard that right.

5
00:00:12,330 --> 00:00:18,300
You can also use templating on classes, not just on member functions.

6
00:00:18,870 --> 00:00:24,570
So why would we want to template a class?

7
00:00:24,840 --> 00:00:33,600
Well, you might encounter a scenario where you want to make some sort of class.

8
00:00:34,540 --> 00:00:43,300
And you want to, let's say, have that glass door like a container of something, or maybe it has some

9
00:00:43,300 --> 00:00:54,280
data members that you define and the thing is, is that you want those data members to be able to take

10
00:00:54,640 --> 00:01:01,120
multiple times, potentially without having to make a different type of code, like what if it's, you

11
00:01:01,120 --> 00:01:08,080
know, we have, for example, like you see, I've declared a pear shaped list agent statelet, simplest

12
00:01:08,150 --> 00:01:08,890
IACP.

13
00:01:08,890 --> 00:01:17,830
So what if we have a list of shapes, but we're not really sure what type of shape it's going to be?

14
00:01:19,190 --> 00:01:28,940
So what I mean by that is that maybe we want the ability to maintain a list of triangles or instead

15
00:01:28,940 --> 00:01:32,810
a list of rectangles or instead a list of circles.

16
00:01:33,770 --> 00:01:36,780
So of course, you could just make a vector and store that in there.

17
00:01:36,800 --> 00:01:41,870
But what if we wanted to make some additional functionality that would be calculated automatically for

18
00:01:41,870 --> 00:01:42,080
us?

19
00:01:42,080 --> 00:01:51,620
Like, maybe this shapeless class could have a function that found the largest area of the shapes in

20
00:01:51,620 --> 00:01:52,970
that list that it had.

21
00:01:52,970 --> 00:01:55,210
So let's say it, the shapeless class.

22
00:01:55,220 --> 00:02:00,860
It has a vector of shapes and maybe, for example, its circles.

23
00:02:00,860 --> 00:02:06,770
It would find you have some function that could find the circle with the largest area out of that list

24
00:02:06,770 --> 00:02:07,430
of circles.

25
00:02:07,880 --> 00:02:15,320
But what if you wanted it to do the exact same thing for rectangles all of a sudden or triangles?

26
00:02:16,280 --> 00:02:22,400
You'll be annoying for you to have to make like a shapeless circle class and a shape list, rectangle

27
00:02:22,400 --> 00:02:24,290
class and a shapeless triangle class.

28
00:02:24,290 --> 00:02:30,080
Just so you can have the same thing, we are doing polymorphisms so we might be able to just use like

29
00:02:30,080 --> 00:02:36,460
the base class shape, but there's also kind of an easier and more intuitive way by using templating.

30
00:02:37,220 --> 00:02:40,820
So let's go ahead and kind of show what's going on here.

31
00:02:40,830 --> 00:02:45,890
So instead of me template right away, let's just make a class called shape list.

32
00:02:47,000 --> 00:02:53,960
What I'm going to do is for the public, and I'll put a private section and let's say we want this vector

33
00:02:54,950 --> 00:02:56,390
of shapes, right?

34
00:02:57,170 --> 00:03:01,130
So I say, Vector, come here and I like Vector.

35
00:03:02,980 --> 00:03:11,590
And let's say I call it a vector shape underscore shapeless like this and come back here and I'm like,

36
00:03:11,590 --> 00:03:14,710
Well, what do I put for the type of the vector?

37
00:03:16,130 --> 00:03:20,300
I don't want to put circle, because then it would only be able to handle circles.

38
00:03:20,330 --> 00:03:24,190
I don't want to put rectangles and could only do that same for triangle, right?

39
00:03:24,200 --> 00:03:26,390
And I'm not including those up here yet either.

40
00:03:27,770 --> 00:03:32,510
So how would I make it be a vector that could handle any one of those things?

41
00:03:33,830 --> 00:03:42,200
Or let's say that I even come up with another shape that somehow, you know, doesn't inherit from this

42
00:03:42,200 --> 00:03:43,070
shape thing, too?

43
00:03:43,100 --> 00:03:49,340
Maybe I come up with a class called line, and it just holds like a bunch of different lines, and it

44
00:03:49,340 --> 00:03:52,220
can tell me like the distances of the lines or something.

45
00:03:52,230 --> 00:03:55,400
So it's not even inheriting from shape.

46
00:03:55,400 --> 00:03:58,070
So we couldn't even use like a basic shape.

47
00:03:58,340 --> 00:04:00,140
Here is the type of the vector, right?

48
00:04:00,740 --> 00:04:06,650
It would just be like its stand alone line class, but we still wanted it to somehow be able to have

49
00:04:06,650 --> 00:04:11,070
a list of lines and consider that to be OK being in the shape list, right?

50
00:04:12,110 --> 00:04:16,110
So there's a way we can do this, and it's by using template, of course.

51
00:04:16,130 --> 00:04:24,350
So just like we have done with the functions, I'm going to write the word template and say Class T.

52
00:04:26,090 --> 00:04:27,680
But it's going to go on top.

53
00:04:27,710 --> 00:04:30,920
You notice here it's on top of the class definition.

54
00:04:33,000 --> 00:04:39,840
So this will enable it so I can put that data type of T in the vector here.

55
00:04:41,140 --> 00:04:47,710
And so this will make it so we can have a vector of circles or instead a vector of squares or sorry

56
00:04:47,710 --> 00:04:52,840
rectangles or triangles without having to make a separate class for each one, we can reuse the same

57
00:04:52,840 --> 00:04:54,850
class for different data types.

58
00:04:56,170 --> 00:05:01,480
So the cool thing about being able to temper the class is it lets us have some data members here that

59
00:05:01,480 --> 00:05:08,530
could potentially be different types, you know, we also might have something, let's say like, you

60
00:05:08,530 --> 00:05:12,370
know, each like shapeless, like the shapeless that we have.

61
00:05:12,370 --> 00:05:19,480
Let's just say like, you know, we have something called like a current shape and this type of team,

62
00:05:19,480 --> 00:05:27,670
we just say like T current, let's say, current shape type or just do like underscore

63
00:05:30,790 --> 00:05:31,800
something like this.

64
00:05:31,810 --> 00:05:34,930
So maybe we are not sure whether it's going to be a.

65
00:05:37,450 --> 00:05:42,540
Circle or a square, something we want to like, take one of the shapes, right?

66
00:05:42,610 --> 00:05:47,980
So if it's a circle, we'll just take like the first circle in the vector and we'll set it to like,

67
00:05:48,400 --> 00:05:50,200
you know, current shape or something.

68
00:05:50,560 --> 00:05:52,900
I don't know, but I'm not going to leave this here.

69
00:05:52,900 --> 00:05:58,480
But just to illustrate the fact that you could do this right, we can even have it declared as a data

70
00:05:58,480 --> 00:06:01,660
type T in our private data remember section.

71
00:06:01,660 --> 00:06:04,720
And just because we've put this template here.

72
00:06:05,500 --> 00:06:08,120
So I'm not going to keep that there because it doesn't seem very sensible.

73
00:06:08,140 --> 00:06:15,010
I'm going to have this vector of type T was the class template type so it can accept anything that comes

74
00:06:15,010 --> 00:06:15,430
into it.

75
00:06:16,000 --> 00:06:17,740
So what else should we put in this class?

76
00:06:17,770 --> 00:06:21,470
I'm going to go ahead and put on a constructor, right?

77
00:06:21,490 --> 00:06:22,930
So I should say shape list.

78
00:06:24,610 --> 00:06:36,340
And then what if we have some cool methods, maybe like I say, like prints, print list or something

79
00:06:36,340 --> 00:06:36,910
like that?

80
00:06:36,910 --> 00:06:40,450
And this'll just like, you know, print the shape list out.

81
00:06:41,050 --> 00:06:44,410
Maybe I say that like largest shape, right?

82
00:06:44,560 --> 00:06:46,330
So what if I want to say?

83
00:06:49,490 --> 00:06:55,070
Look, I want to say that we will return the largest shaved or something like that, so I could say

84
00:06:55,070 --> 00:07:10,280
that we will do so return T and I will say like get largest shape, maybe get larger shape out of that

85
00:07:10,850 --> 00:07:11,240
vector.

86
00:07:11,240 --> 00:07:15,830
So it'll, you know, find whatever shape it is and return the largest, the one with the largest area.

87
00:07:17,560 --> 00:07:21,580
And we'll, of course, maybe want something to add it to the list, right?

88
00:07:21,600 --> 00:07:26,060
So what if I say add shape, right?

89
00:07:26,080 --> 00:07:29,850
And then this will take in some type of shape.

90
00:07:29,860 --> 00:07:33,110
We're going to use Ti again because we're not sure what the shape type might be.

91
00:07:33,130 --> 00:07:34,990
We're just going to use our template type for that.

92
00:07:35,440 --> 00:07:38,860
So let's say the parameter will be typed.

93
00:07:40,000 --> 00:07:43,600
So I'm just going to say shape right here.

94
00:07:43,640 --> 00:07:44,590
I'll say s.

95
00:07:47,810 --> 00:07:48,300
Cool.

96
00:07:48,320 --> 00:07:51,230
So this kind of gives us everything here.

97
00:07:51,710 --> 00:08:00,350
And so one, before I generate these function definitions, I want to kind of point out some important

98
00:08:00,350 --> 00:08:01,310
details.

99
00:08:02,240 --> 00:08:10,430
So one thing that we're going to have to do if we have the template here in the header file and we have

100
00:08:10,430 --> 00:08:21,860
a separate zip file is that this may seem weird, but instead of us putting like some of them in here

101
00:08:21,860 --> 00:08:30,150
instead of us doing in the CBP include the shape forms and spell.

102
00:08:30,150 --> 00:08:34,340
That right include shape, Lester age.

103
00:08:34,910 --> 00:08:36,920
We're not going to put that in here.

104
00:08:36,950 --> 00:08:39,710
Instead, we're going to do the complete reverse.

105
00:08:40,160 --> 00:08:43,340
And here we are going to say

106
00:08:45,530 --> 00:08:53,330
include down here and we're going to say shape list dot CVP.

107
00:08:55,430 --> 00:08:57,740
And why are we going to do that?

108
00:08:57,770 --> 00:09:04,970
Well, it's a problem with the templating, if we template the header file here and we decide not to

109
00:09:04,970 --> 00:09:08,730
put the implementation in the same file.

110
00:09:09,860 --> 00:09:16,470
Then things have to be flipped around, so the compiler will know how to generate everything correctly.

111
00:09:16,490 --> 00:09:22,670
So for that reason, you have to have the definition here in the header file.

112
00:09:22,670 --> 00:09:28,760
So put all your prototypes and everything in the header file here and underneath that, but before the

113
00:09:28,760 --> 00:09:31,010
macro guard stuff finishes.

114
00:09:31,280 --> 00:09:33,380
So, you know, you make sure to put this as well.

115
00:09:33,380 --> 00:09:34,340
Put your macro guys.

116
00:09:34,340 --> 00:09:40,550
But before you have this, and if and after the class definition, you should have it include and then

117
00:09:40,700 --> 00:09:44,180
the CPE implementation file.

118
00:09:45,080 --> 00:09:50,110
You also can just ignore, you know, totally not new separate files.

119
00:09:50,120 --> 00:09:56,090
And if you wanted to, you could erase this, you know, and just take everything that you would put

120
00:09:56,090 --> 00:10:01,940
in this heap and just start, you know, typing it right here, you know, paste it right.

121
00:10:01,940 --> 00:10:05,930
There have all the implementation in the same file, and that's totally fine as well.

122
00:10:05,960 --> 00:10:09,010
I just want to show you how you can do it both ways, you know?

123
00:10:10,670 --> 00:10:14,120
So I'm going to include this checklist CBP here.

124
00:10:15,290 --> 00:10:23,520
Another important thing about Sea Lion is that you're going to want to make sure that the shape lists

125
00:10:23,540 --> 00:10:29,710
H and shape list copy whatever the template files are.

126
00:10:29,720 --> 00:10:33,460
You know, anything that has to do with templates if they're in separate files.

127
00:10:33,470 --> 00:10:40,280
Of course, you're going to want to have to go one or want to go over here to see make lists, and you're

128
00:10:40,280 --> 00:10:45,320
going to want to make sure that they're not listed here in this ad executable section.

129
00:10:45,350 --> 00:10:49,940
They should not be added as targets to the build process.

130
00:10:49,970 --> 00:10:51,440
You know, this is what this is.

131
00:10:51,440 --> 00:10:56,690
The build process like a file, one of the files that's needed to successfully compile the projects

132
00:10:56,690 --> 00:11:03,040
here and you list your target files to compile, but you're not going to want to have shape list or

133
00:11:03,050 --> 00:11:06,030
shape list CPP listed in here.

134
00:11:06,050 --> 00:11:09,200
Otherwise, it's most likely going to throw some errors.

135
00:11:10,540 --> 00:11:12,250
So I want to point that out as well.

136
00:11:14,370 --> 00:11:19,860
So if you're not working on here, just make sure that you're like, if you're using some other type

137
00:11:19,860 --> 00:11:26,280
of make file or something to compile, just make sure that you're including only the other files as

138
00:11:26,280 --> 00:11:27,090
targets.

139
00:11:27,480 --> 00:11:29,940
This will just be considered a library.

140
00:11:30,390 --> 00:11:31,310
It'll work out.

141
00:11:31,320 --> 00:11:37,080
Don't worry, the CP doesn't need to be compiled because this is being included here instead.

142
00:11:37,860 --> 00:11:39,130
All you have to do.

143
00:11:39,280 --> 00:11:43,320
I'll show you this once we get to main is just include the header and main.

144
00:11:44,980 --> 00:11:50,590
And it's automatically just going to all work out, it'll go through here, it will use it as like another

145
00:11:50,590 --> 00:11:55,840
library that gets imported without you having to compile it and have these files as targets so don't

146
00:11:56,290 --> 00:11:57,580
don't include them as targets.

147
00:11:58,300 --> 00:12:02,050
So let's go ahead and generate some ecotourism and generate a definition.

148
00:12:05,350 --> 00:12:11,920
And it's not putting it in the air, so let me just generate it and copy it, so I'm going to go over

149
00:12:11,920 --> 00:12:19,000
here and I'm just going to copy it here and then I'll go here and generate this definition.

150
00:12:20,560 --> 00:12:22,990
All right, cool now it went ahead and put it in there.

151
00:12:23,020 --> 00:12:30,130
I don't want it to include this, though, so I'm going to get rid of that once I once I do this, so

152
00:12:30,130 --> 00:12:31,600
generate a function for this.

153
00:12:33,770 --> 00:12:37,250
And let's go ahead and generate a function for this.

154
00:12:41,810 --> 00:12:42,260
Cool.

155
00:12:42,620 --> 00:12:47,420
So what I'm going to do now is go up here and definitely get rid of this because we don't want to include

156
00:12:47,420 --> 00:12:47,720
that.

157
00:12:50,750 --> 00:12:58,940
And so you notice that when I generated it, it put this template class T on top of the member functions.

158
00:12:59,450 --> 00:13:06,380
Also notice that it went ahead and instead of just putting shape list for the scope resolution part,

159
00:13:07,160 --> 00:13:12,950
you know, here's the scope resolution operator for the name of the class input shape list and T right

160
00:13:12,950 --> 00:13:13,230
here.

161
00:13:13,250 --> 00:13:15,170
So this is another part of the syntax.

162
00:13:15,500 --> 00:13:18,410
If I click this right here, it will expose this template.

163
00:13:19,010 --> 00:13:22,170
So this is another part of the syntax that's important.

164
00:13:22,190 --> 00:13:28,220
So when you do this class, every function, even though you're not really thinking about them as being

165
00:13:28,220 --> 00:13:35,120
templated functions, you need to have a template syntax.

166
00:13:35,450 --> 00:13:39,320
And this is well on every one of the member functions here.

167
00:13:39,350 --> 00:13:39,770
OK.

168
00:13:40,100 --> 00:13:40,970
And that does this.

169
00:13:40,970 --> 00:13:45,980
Regardless of whether you're using separate files or putting the implantation in this header file,

170
00:13:46,340 --> 00:13:50,990
you're still going to need this template class T over all the functions, and you're still going to

171
00:13:50,990 --> 00:13:54,770
want to put this part here for this scope resolution.

172
00:13:56,090 --> 00:13:58,100
So just want to make sure that that's very clear.

173
00:14:00,390 --> 00:14:01,070
All right, cool.

174
00:14:01,120 --> 00:14:06,090
So you notice this stuff highlighted just because I'm already using this in Maine and I'll show you

175
00:14:06,090 --> 00:14:08,010
the code that I'm using in that client file.

176
00:14:09,450 --> 00:14:13,590
So let's go ahead and implement some of the logic for this stuff right here.

177
00:14:14,220 --> 00:14:18,300
So I'm going to come in here for shape list what I actually want to do.

178
00:14:18,300 --> 00:14:23,670
I'm going to make an initialization list for this constructor, and I'm just going to say shape list

179
00:14:23,670 --> 00:14:30,210
or vector should just be a new vector of type T.

180
00:14:30,210 --> 00:14:30,830
Like this?

181
00:14:30,850 --> 00:14:35,850
I'll use the Vector Ops Vector Constructor, right?

182
00:14:35,860 --> 00:14:39,820
So this is going to be my initialization list style constructor.

183
00:14:39,840 --> 00:14:45,720
So this will make a new vector here of type T and set our data member shapeless to that.

184
00:14:47,310 --> 00:14:53,970
So add shape takes shape and all we're going to do is, say, shapeless start, push back and s.

185
00:14:54,420 --> 00:14:56,480
And so this is type T, right?

186
00:14:56,490 --> 00:14:58,200
This is already Typekit here here.

187
00:14:58,200 --> 00:15:05,760
So it's going to be able to add that, OK, cool work for any shape for this print list I'm going to

188
00:15:05,760 --> 00:15:06,480
go through.

189
00:15:06,630 --> 00:15:11,850
I will do kind of an item based loop here with the auto keyword.

190
00:15:11,850 --> 00:15:23,520
So I'll just say auto S4 shape in shape list and then I'll go ahead and see out the let's see.

191
00:15:23,520 --> 00:15:27,840
We'll do the shape list color of maybe first.

192
00:15:27,850 --> 00:15:30,630
So I'll say s dot

193
00:15:33,420 --> 00:15:34,980
get color and get color.

194
00:15:34,980 --> 00:15:35,910
Is that what it is?

195
00:15:38,650 --> 00:15:39,460
Get color.

196
00:15:39,730 --> 00:15:40,560
Okay, cool.

197
00:15:42,800 --> 00:15:49,400
Escort get color so this can be like blue, and then let's say like we do a little space and then we'll

198
00:15:49,400 --> 00:15:51,930
say, like an escort.

199
00:15:53,120 --> 00:15:54,060
Is it type?

200
00:15:54,300 --> 00:15:56,930
She was going here to see that type.

201
00:15:57,960 --> 00:15:58,380
Right.

202
00:15:59,510 --> 00:16:06,170
So type, so this could be like, you know, like blue rectangle,

203
00:16:09,380 --> 00:16:20,450
and we'll just say with area and I'll say S-type area.

204
00:16:24,650 --> 00:16:27,830
And then we'll do an incline.

205
00:16:30,200 --> 00:16:34,130
Cool, so I just want to print out some info about each shape, right?

206
00:16:34,190 --> 00:16:37,010
So I have this kind of bass loop.

207
00:16:37,010 --> 00:16:39,470
I'm using the other keyword, so it resolves to the type.

208
00:16:40,430 --> 00:16:45,440
And then it goes through shapeless Australian, and so for every shape in the shape list, it's going

209
00:16:45,440 --> 00:16:47,560
to say the shape, get color.

210
00:16:47,570 --> 00:16:53,870
So for example, this could be blue and then a space, and that's going to say the type.

211
00:16:53,870 --> 00:16:59,660
So like Blue Circle Width area, and then it'll print out the shapes area so we can print out all the

212
00:16:59,660 --> 00:17:02,570
info and loop through all the list of the shapes that we have.

213
00:17:03,530 --> 00:17:04,970
You get larger shape.

214
00:17:05,000 --> 00:17:11,610
I think I'm going to do something like where I make some temporary variable and it's just going to come

215
00:17:11,660 --> 00:17:15,680
called like the largest in index or sea index.

216
00:17:18,430 --> 00:17:22,120
So how about I say largest index equals zero?

217
00:17:23,110 --> 00:17:31,090
So we'll start at zero and then I'll say four and I equals zero is less than

218
00:17:34,210 --> 00:17:38,680
shapeless size I have plus plus.

219
00:17:39,880 --> 00:17:45,310
And then what we'll do is say if let's see.

220
00:17:45,310 --> 00:17:50,140
So if shape list I.

221
00:17:53,120 --> 00:18:07,820
Dot area is greater than the shape list and the largest index dot area.

222
00:18:09,050 --> 00:18:13,580
So what I'm checking right here is I'm saying like it's the current shape that we're on and the list

223
00:18:13,580 --> 00:18:19,370
is it's area greater if its area is greater than.

224
00:18:20,670 --> 00:18:23,730
The largest one so far, right?

225
00:18:24,240 --> 00:18:28,080
So I start watching this is zero, but I'll just keep updating the largest one.

226
00:18:30,090 --> 00:18:35,310
So I'm saying if it's larger than the current largest, then we'll just go ahead and save it.

227
00:18:35,760 --> 00:18:42,450
The largest index equals I will change the index of that right?

228
00:18:42,450 --> 00:18:45,300
And then that way we can update that.

229
00:18:46,050 --> 00:18:48,000
Update the index as the largest one.

230
00:18:50,080 --> 00:18:50,470
Cool.

231
00:18:50,800 --> 00:18:59,380
So, otherwise, it'll just keep going through, and then at the end, I'll just say return ship list

232
00:18:59,950 --> 00:19:06,190
and I'll say largest, I'd say the largest index, so that would be able to get the largest shape for

233
00:19:06,190 --> 00:19:06,490
us.

234
00:19:08,850 --> 00:19:11,400
And I think that's kind of all I want to add right now.

235
00:19:15,650 --> 00:19:16,150
Yeah.

236
00:19:16,880 --> 00:19:23,010
So we will go over to Maine now, and we'll kind of test some of the stuff out.

237
00:19:23,030 --> 00:19:24,080
I already have some code there.

238
00:19:24,080 --> 00:19:28,250
I'm going to change a little bit because I kind of renamed this.

239
00:19:29,360 --> 00:19:31,610
So let's go ahead and check this out.

240
00:19:31,610 --> 00:19:37,160
So I kind of have these pointers left here, but I'm going to make some more variables that aren't pointers.

241
00:19:38,030 --> 00:19:40,640
So I have like some circles and rectangles, for example.

242
00:19:41,540 --> 00:19:45,830
And so let's talk about how we can now make a shape list object.

243
00:19:45,860 --> 00:19:46,730
So first of all.

244
00:19:47,960 --> 00:19:52,700
You're going to want to include the simplest header up here, just like any normal header, like, you

245
00:19:52,700 --> 00:19:53,810
know, these ones.

246
00:19:54,870 --> 00:20:02,010
And then what I'm doing is first, I'm making, like I said, some non pointer objects of rectangle

247
00:20:02,010 --> 00:20:02,610
and circle.

248
00:20:03,570 --> 00:20:10,890
I go here and I say shape list, and then I put the type here.

249
00:20:11,100 --> 00:20:17,580
The explicit type here because shapeless expects since templated, it's kind of like a vector, right?

250
00:20:18,090 --> 00:20:22,650
It expects you to put the type that you want to be associated with the class.

251
00:20:22,680 --> 00:20:30,810
So this object, this shapeless object I'm calling SLC for shapeless circle is of type circle.

252
00:20:31,200 --> 00:20:38,060
Yet I'm still able to use the shapeless class to create a rectangle version of it.

253
00:20:38,070 --> 00:20:41,170
And I have a special object now that is shapeless rectangle.

254
00:20:41,970 --> 00:20:46,890
So this area after so here's the class name, right data type name.

255
00:20:46,890 --> 00:20:49,440
But also a part of that is the template.

256
00:20:49,450 --> 00:20:55,560
So you put the class name, then you put the template type in the angle brackets and then you can put

257
00:20:55,560 --> 00:20:58,710
the name of the variable right in the variable name.

258
00:20:59,160 --> 00:21:01,100
Same thing here for rectangle, right?

259
00:21:01,110 --> 00:21:08,400
So I have two different types shape list circles, shapeless rectangle, and I'm calling them appropriately.

260
00:21:08,400 --> 00:21:12,660
And the way that I'm doing that is through this angle bracket template type here.

261
00:21:14,500 --> 00:21:21,280
So I'm going to change this to print list instead of print shapes, assistance or other stuff earlier,

262
00:21:21,280 --> 00:21:24,070
so we're going to change this to print list.

263
00:21:27,250 --> 00:21:28,390
What else should we do?

264
00:21:28,420 --> 00:21:33,970
Maybe we can say largest shape or something like that, so.

265
00:21:37,330 --> 00:21:40,330
Maybe it will print the area of the largest ship.

266
00:21:41,140 --> 00:21:46,750
So let's just say we print the list and then after this, we'll say, like SLC.

267
00:21:47,380 --> 00:21:49,870
Uh, let's see.

268
00:21:50,890 --> 00:21:53,800
See, see out SLC.

269
00:21:55,040 --> 00:21:55,700
Dot.

270
00:21:58,550 --> 00:22:01,820
Uh, get larger shape.

271
00:22:01,840 --> 00:22:03,670
Dot area.

272
00:22:06,940 --> 00:22:07,690
How about that?

273
00:22:07,930 --> 00:22:09,760
And I will put this.

274
00:22:09,970 --> 00:22:17,650
Copy paste this here and after this print list, I'll just change it to SLR so I can get the largest

275
00:22:17,650 --> 00:22:18,640
of the rectangles too.

276
00:22:19,000 --> 00:22:22,810
So you notice I'm also d referencing one of these pointers up here.

277
00:22:22,810 --> 00:22:29,950
So this circle I just consider see one in this rectangle I was considered kind of like as if it would

278
00:22:29,950 --> 00:22:32,890
be R one, but I'm using the pointers.

279
00:22:32,890 --> 00:22:40,990
But what I'm doing is I'm passing them as d referenced to this shape because you know that over here

280
00:22:42,160 --> 00:22:49,150
we when we add the shape, we expect it to not be a pointer just to be, you know, a normal object

281
00:22:49,610 --> 00:22:50,420
of type T..

282
00:22:51,010 --> 00:22:54,940
You can also do it with pointers to we could rearrange this and do it.

283
00:22:54,940 --> 00:22:59,020
But just for simplicity of step, I think I'm just kind of like doing it like this.

284
00:22:59,650 --> 00:23:01,630
So let's go over here.

285
00:23:02,530 --> 00:23:05,320
So you notice there, I d reference that that's why this star is there.

286
00:23:05,840 --> 00:23:10,720
Same for the rectangle just referencing these pointers up here so I can pass a normal object.

287
00:23:10,930 --> 00:23:12,880
Let's go ahead and run this and see what we get.

288
00:23:20,580 --> 00:23:22,680
OK, so pretty cool, right?

289
00:23:22,740 --> 00:23:23,220
Let's go ahead.

290
00:23:23,280 --> 00:23:24,660
Let me zoom in on this here.

291
00:23:26,010 --> 00:23:35,040
So we get a green circle with Area 277, Blue Circle with Area 47 and Black Circle with Area 191.

292
00:23:35,400 --> 00:23:41,280
We see that the biggest one was 277, so that worked out and found the correct one.

293
00:23:42,510 --> 00:23:44,240
You know, the rectangle as well.

294
00:23:44,250 --> 00:23:45,360
We see all these.

295
00:23:45,870 --> 00:23:49,500
And it found the largest one for the rectangle as well.

296
00:23:50,760 --> 00:23:52,770
So let's just compare that to what we were up here.

297
00:23:54,600 --> 00:23:57,930
Seems to be pretty good, at least these are.

298
00:24:00,560 --> 00:24:07,430
Correct, right, so we have a green of blue and a black green, blue, black and red and purple purple,

299
00:24:07,430 --> 00:24:07,800
purple.

300
00:24:07,820 --> 00:24:08,660
These are all purple.

301
00:24:10,520 --> 00:24:12,440
So pretty cool.

302
00:24:12,740 --> 00:24:17,240
So I didn't test it with the triangle, but it totally be fine with the triangle as well.

303
00:24:19,100 --> 00:24:24,650
I used the print list, the ad shape and the get larger shape, so we tested all three of those.

304
00:24:25,920 --> 00:24:33,540
And so the main takeaway is just the syntax here and the idea that you can use the template on a class

305
00:24:33,540 --> 00:24:34,260
as well.

306
00:24:34,950 --> 00:24:36,840
So it's definitely a powerful tool.

307
00:24:36,870 --> 00:24:45,660
Templating is kind of one of the coolest things that you can do in C++, and it really makes it a kind

308
00:24:45,660 --> 00:24:52,260
of competitor with some of the more modern languages that kind of have these automatic and more dynamic

309
00:24:52,260 --> 00:24:54,570
systems with typing and stuff like that.

310
00:24:55,950 --> 00:25:05,550
So with that, I am going to leave you with what we talked about so far in this lecture and not go any

311
00:25:05,790 --> 00:25:14,070
further with this, but you should be able to look back on this and understand how to deal with the

312
00:25:14,640 --> 00:25:16,350
templated classes as well.

313
00:25:16,350 --> 00:25:22,830
Remember some of the important points that are kind of little important details like including the copy

314
00:25:23,070 --> 00:25:28,830
in the header, rather than including the header in the CP whenever you're doing separate files for

315
00:25:28,830 --> 00:25:29,490
the templates.

316
00:25:30,060 --> 00:25:36,540
Also, if you're using Feli and make sure to not have those two files in the targets if you're doing

317
00:25:36,540 --> 00:25:40,470
separate files and that means don't have them in this list here in the see make lists.

318
00:25:42,340 --> 00:25:47,170
And if you're working in something else, just don't have them in the targets to whatever the building

319
00:25:47,170 --> 00:25:50,330
process is, if you're using make and making make files.

320
00:25:50,350 --> 00:25:53,020
Good for you, but just don't put those targets.

321
00:25:54,400 --> 00:26:00,790
And just to let you know you can take all the CBP code and just remove this highlighted line and put

322
00:26:00,790 --> 00:26:02,770
it in here and have it all in one file.

323
00:26:04,390 --> 00:26:11,590
So with that, we are nearing the end of this half, first half of the course.

324
00:26:11,980 --> 00:26:18,010
We've talked about almost everything there is in basic programming and syntax for C++.

325
00:26:18,860 --> 00:26:23,140
I am going to have one final project for you to do.

326
00:26:23,380 --> 00:26:29,500
And then after that, there will be the second half of the course, which will be all about data structures

327
00:26:29,500 --> 00:26:30,600
and algorithms.

328
00:26:30,610 --> 00:26:35,770
We will continue using C++ and we will be putting a lot of this stuff to use.

329
00:26:36,130 --> 00:26:41,800
In fact, we will be using templating for the first data structures that we go over.

330
00:26:41,830 --> 00:26:46,240
We will need to use templates to deal with those.

331
00:26:46,330 --> 00:26:50,380
We're going to use that just so we can practice as well.

332
00:26:50,950 --> 00:26:55,030
So you feel comfortable, more comfortable with templates as we move on.

333
00:26:55,480 --> 00:26:59,620
We won't be using templates all the time, but we will try and get some practice.

334
00:26:59,620 --> 00:27:00,610
So you feel comfortable.

335
00:27:01,510 --> 00:27:01,990
OK.

336
00:27:02,020 --> 00:27:04,870
So with that, I will see you in the next lecture.
