1
00:00:00,270 --> 00:00:05,130
So welcome back to another lesson, everybody in this lesson today, we're going to be continuing on

2
00:00:05,580 --> 00:00:09,600
with our discussion about overloading operators and C++.

3
00:00:10,620 --> 00:00:13,320
We left off talking about the assignment operator.

4
00:00:15,170 --> 00:00:19,530
Now we are going to move on to some other operators specifically in this lecture.

5
00:00:19,530 --> 00:00:24,120
We are going to talk about some mathematical operators.

6
00:00:24,120 --> 00:00:30,510
So binary mathematic operators like plus minus, you know, when you have something like something else,

7
00:00:30,510 --> 00:00:35,460
something minus something else, multiply stuff like that.

8
00:00:35,460 --> 00:00:42,900
So I'm really just going to go over the code for the plus or addition operator, overloaded operator.

9
00:00:43,890 --> 00:00:50,010
And then we'll just kind of talk about how it would be easy to transition into doing the subtraction

10
00:00:50,010 --> 00:00:55,530
operator or the multiplication operator where we're rolling forward with our car class just so we can

11
00:00:55,530 --> 00:00:56,550
add functionality.

12
00:00:56,550 --> 00:01:04,290
And so it'll be kind of fresh for you because we've been using the car class and I think you're kind

13
00:01:04,290 --> 00:01:09,930
of putting together all the pieces in your head, how all these files work together, how all this code

14
00:01:09,930 --> 00:01:12,060
works together, and we're kind of building on that.

15
00:01:12,070 --> 00:01:20,460
I think switching to a new kind of topic, some abstraction or new ADT would be a little just confusing,

16
00:01:20,790 --> 00:01:26,250
pointlessly confusing, you know, so let's go ahead and get started.

17
00:01:26,260 --> 00:01:30,240
So what we're going to talk about is this plus operators.

18
00:01:30,240 --> 00:01:34,110
So I have some code here and mean CP that's commented out.

19
00:01:34,530 --> 00:01:40,170
And what it's really doing is it's it's it's adding some upgrades, it's showing some upgrades.

20
00:01:40,170 --> 00:01:43,350
So this is actually a new function that I added and I'll show you that in a second.

21
00:01:43,350 --> 00:01:45,390
It just shows you what upgrades the car has.

22
00:01:46,620 --> 00:01:52,350
And then what we're going to do is something like this where we're going to add a car and another car

23
00:01:52,380 --> 00:01:59,710
is going to have a result and we're going to save that result in an existing car in this example.

24
00:01:59,730 --> 00:02:04,050
So here is the assignment operator being used, and we've already handled that.

25
00:02:04,380 --> 00:02:13,470
But right here is we'll need to overload the plus operator because C++ does not know by default how

26
00:02:13,470 --> 00:02:18,570
to add to objects here that you have defined, right?

27
00:02:18,570 --> 00:02:19,920
It's user defined object.

28
00:02:19,920 --> 00:02:20,510
It's a car.

29
00:02:20,520 --> 00:02:23,970
It's not a standard data type of the language.

30
00:02:24,600 --> 00:02:28,680
So that's why we're going to have to overload the operator for this segment right here.

31
00:02:29,310 --> 00:02:35,940
And we're going to need to return the result of a car being added to a car, which will be another car.

32
00:02:35,950 --> 00:02:41,100
So we're going to have to decide what that really means when you add cars together, like what does

33
00:02:41,100 --> 00:02:41,340
that?

34
00:02:41,340 --> 00:02:42,030
What does that mean?

35
00:02:42,030 --> 00:02:43,980
It's this really makes sense right off the bat, right?

36
00:02:43,980 --> 00:02:49,320
Because, you know, you add numbers together, that kind of makes sense.

37
00:02:49,740 --> 00:02:51,690
But like, what would a car plus a car be?

38
00:02:52,050 --> 00:02:53,120
So we'll discuss that.

39
00:02:53,130 --> 00:02:57,300
I'm actually going to go over a really like kind of basic interpretation.

40
00:02:57,300 --> 00:03:01,620
There's probably better ways you could add cars together, but for simplicity's sake, I'm going to

41
00:03:01,620 --> 00:03:04,240
make a very simple addition.

42
00:03:04,260 --> 00:03:04,950
Operator.

43
00:03:05,730 --> 00:03:06,270
Very simple.

44
00:03:06,270 --> 00:03:07,290
Plus operator here.

45
00:03:08,640 --> 00:03:12,660
So let's hop over to Card CP.

46
00:03:12,690 --> 00:03:16,500
So what I've done is I have this show upgrades function.

47
00:03:16,800 --> 00:03:18,590
It's void return type.

48
00:03:18,600 --> 00:03:21,810
All it does is it goes through the.

49
00:03:23,670 --> 00:03:33,840
Vector here, so this is actually a kind of an item base loop here that's going over all of the items

50
00:03:33,840 --> 00:03:34,760
in upgrade code.

51
00:03:34,770 --> 00:03:36,720
So I is the actual item.

52
00:03:37,080 --> 00:03:42,570
It's using this as kind of some slightly more modern syntax, but I'm using the auto keyword to detect

53
00:03:42,570 --> 00:03:46,260
the type of AI and then what that's going to be.

54
00:03:46,260 --> 00:03:52,200
This colon is basically saying that is going to take the form of each of the things inside upgrade codes.

55
00:03:52,200 --> 00:03:59,400
And you notice that I'm d referencing a great codes because upgrade codes is in fact a pointer.

56
00:04:01,480 --> 00:04:02,410
Pointed to a vector.

57
00:04:03,490 --> 00:04:07,930
So then it just prints each one of them out that way you can see the upgrade occurs and kind of see

58
00:04:07,930 --> 00:04:08,890
how it changed.

59
00:04:09,100 --> 00:04:14,950
If we add things and then we add the cars together, we want to see the before and after to make sure

60
00:04:14,950 --> 00:04:17,380
that our function did what was expected.

61
00:04:18,190 --> 00:04:21,050
And you can actually go over that in the debugger as well.

62
00:04:21,070 --> 00:04:31,420
I actually did set up my voice code to have a graphical debugger now and have a compiler, so I might

63
00:04:31,420 --> 00:04:35,050
be going over that in some future lectures on how to set that up.

64
00:04:35,650 --> 00:04:39,350
But you can essentially have a graphical debugger like sea lion.

65
00:04:39,370 --> 00:04:45,160
It's definitely not as good as sea lion, just kind of out of the box.

66
00:04:45,550 --> 00:04:52,360
The sea lion debugger seems to be have a lot more features and tools and be more user friendly.

67
00:04:53,710 --> 00:04:55,690
I'm sure some people would argue me about that.

68
00:04:55,690 --> 00:05:03,730
The code has just as good a debugger, but so far it seems like the sea lion one was a bit nicer.

69
00:05:03,850 --> 00:05:08,260
As far as the graphical debugger, anyways, that's a tangential kind of topic.

70
00:05:08,260 --> 00:05:11,770
So let's get back to talking about our Plus operator.

71
00:05:11,770 --> 00:05:14,560
So we're going to do is put it right here in the CBP file.

72
00:05:14,770 --> 00:05:19,660
But first, we're going to go ahead and define a prototype that's in the public section of our header

73
00:05:19,660 --> 00:05:20,530
file up here.

74
00:05:21,790 --> 00:05:27,340
So since we're adding a car plus another car is going to turn returning some result car.

75
00:05:27,400 --> 00:05:29,410
So I'm going to say the return type is car.

76
00:05:29,770 --> 00:05:31,510
I don't need to return it by reference.

77
00:05:31,510 --> 00:05:35,470
I'm actually just going to skip this ampersand and just put operator here.

78
00:05:36,610 --> 00:05:43,270
So I'm going to say because it's going to be like a new car, I don't I might not necessarily make a

79
00:05:43,270 --> 00:05:49,660
new card type, but I'm going to return just a car type, not something by reference where here we needed

80
00:05:49,660 --> 00:05:54,910
it, by reference because we are assigning things to the this object, right?

81
00:05:55,450 --> 00:05:57,640
The object that is being called upon.

82
00:05:58,150 --> 00:06:00,640
We'll see how that comes into play in this plus upgrade as well.

83
00:06:01,150 --> 00:06:03,910
So this is going to be operator plus instead of an equal sign.

84
00:06:04,750 --> 00:06:11,580
And then what I'm going to do here is I'm just going to say I can make this contest.

85
00:06:11,590 --> 00:06:16,960
I can say cost, car and object.

86
00:06:18,130 --> 00:06:21,190
So it's going to be similar to the parameters of this.

87
00:06:22,960 --> 00:06:29,140
Assignment operator, this is all we need for the prototype, and then I'm going to head over to the

88
00:06:29,140 --> 00:06:31,630
implementation file here, and we're going to get started.

89
00:06:32,080 --> 00:06:37,360
So remember return type as car and then I need to put scope resolution for the car class.

90
00:06:37,960 --> 00:06:45,520
And then what I want to do now is add my plus operator so I can score their interests have and then

91
00:06:45,520 --> 00:06:48,610
we need to put our concept car.

92
00:06:49,030 --> 00:06:52,630
And this is going to be passed by reference because we want to pass the actual object.

93
00:06:53,740 --> 00:06:58,720
So this is like the one that we're going to be adding, like right hand side, left hand side.

94
00:07:00,790 --> 00:07:05,370
And so what I'm going to do now, this is going to be a really simple plus operator.

95
00:07:05,380 --> 00:07:09,820
So normally it'll probably be better to maybe like.

96
00:07:11,040 --> 00:07:22,710
Go through all of the upgrade codes of the object in the parameter and this object, you know, that's

97
00:07:22,710 --> 00:07:23,880
being called upon.

98
00:07:24,360 --> 00:07:29,490
So that would just be, you know, like if we're talking about upgrades, codes, there's the object,

99
00:07:30,180 --> 00:07:30,540
right?

100
00:07:30,540 --> 00:07:41,190
There's its upgrade codes, and then there's this upgrade codes, something like that, you know, which

101
00:07:41,190 --> 00:07:44,580
is just basically the same as saying, OK, codes.

102
00:07:46,230 --> 00:07:52,890
So what would probably be the best bus operator is to, like, make a union of those two vectors and

103
00:07:52,890 --> 00:08:00,360
by union, you know, we're talking about like, you know, if anything doesn't exist in the other,

104
00:08:00,660 --> 00:08:07,290
then we'll go ahead and add it to this like new vector or something, right?

105
00:08:07,530 --> 00:08:12,780
So we want like a combination of all of the unique elements and both.

106
00:08:13,320 --> 00:08:15,360
So we're not going to have any repeated elements.

107
00:08:15,360 --> 00:08:24,780
But like, let's say one vector has the upgrade codes like one and two, and the other one has one,

108
00:08:26,610 --> 00:08:27,930
three and four.

109
00:08:28,380 --> 00:08:34,530
So we have one and two and one, three and four that the union of those would be like one two three

110
00:08:34,530 --> 00:08:35,010
four.

111
00:08:35,490 --> 00:08:35,830
Right.

112
00:08:35,850 --> 00:08:38,130
It's not going to be like one one two three four.

113
00:08:39,030 --> 00:08:43,320
Just because there's a one in and one of them and a one in the other one.

114
00:08:43,770 --> 00:08:49,560
It's just like all of those non repeating elements kind of clumped together so that that would be like

115
00:08:49,560 --> 00:08:54,840
an ideal place operator, but for simplicity's sake, I'm just going to do.

116
00:08:55,970 --> 00:09:04,050
A plus operator where we literally just see which car has more upgrade codes, so just like this object,

117
00:09:04,230 --> 00:09:05,610
have more upgrade codes.

118
00:09:06,060 --> 00:09:12,990
Or does OBJ have more upgrade codes and we're just going to return whatever car has more upgrade codes,

119
00:09:12,990 --> 00:09:14,940
so this can be someone like.

120
00:09:17,280 --> 00:09:23,010
You know, having some type of car and they're like, Oh, this, you know, this guy's car has more

121
00:09:23,010 --> 00:09:30,480
stuff like, I want that car, so this is like not necessarily the most sensical plus operator, but

122
00:09:30,660 --> 00:09:33,200
we can write whatever code we want in here.

123
00:09:33,210 --> 00:09:41,790
So it's kind of almost like a greater than operator, but it doesn't just say that it's greater than

124
00:09:41,790 --> 00:09:43,860
another car and say true or false.

125
00:09:43,860 --> 00:09:50,130
It really just gives like the bigger list of the car that has a bigger list of upgrades back.

126
00:09:50,670 --> 00:09:57,570
But one thing that I want this to be contingent upon is that the model and the brand are the same.

127
00:09:57,960 --> 00:10:04,920
So like if someone you know, if we have a Ford Fiesta and we're like, Oh, Ford Fiesta plus Lamborghini,

128
00:10:05,340 --> 00:10:10,600
you know, and the Lamborghini has more upgrades, then we just get a Lamborghini.

129
00:10:10,620 --> 00:10:12,480
Suddenly, you know, that doesn't really make sense.

130
00:10:12,480 --> 00:10:17,780
So we're going to only do this if the car is.

131
00:10:19,910 --> 00:10:28,490
It's the model and make of this car that we're adding to, the left hand side is the same as that this

132
00:10:28,490 --> 00:10:28,940
object.

133
00:10:30,200 --> 00:10:31,760
So let's go ahead and do that.

134
00:10:31,760 --> 00:10:35,390
So I went for a conditional check here and I'm going to say if.

135
00:10:38,780 --> 00:10:43,430
Model, so this is basically similar to this Arrow model.

136
00:10:45,150 --> 00:10:59,120
The call called upon object, so I'm going to say if a model is equal to object model and brand is equal

137
00:10:59,120 --> 00:11:06,310
to object brand, then we're good to go.

138
00:11:06,320 --> 00:11:10,010
We can go ahead and try and figure out which one has more stuff.

139
00:11:10,010 --> 00:11:17,540
So what we will say is we'll say, OK, well, if the

140
00:11:20,210 --> 00:11:26,570
upgrade codes aero size because remember, upgrade codes is a pointer.

141
00:11:27,080 --> 00:11:34,460
If that is greater than or equal to the.

142
00:11:37,860 --> 00:11:42,210
Let's see, so if that is greater than or equal to the

143
00:11:45,110 --> 00:11:45,540
object.

144
00:11:46,110 --> 00:11:46,460
Sorry.

145
00:11:47,020 --> 00:11:55,410
Know, you know, so if the objects of Great Code's size right, then we want to return that bigger

146
00:11:55,410 --> 00:11:57,800
one, right, which is the upgrade code size.

147
00:11:57,810 --> 00:11:59,700
So I don't even need these brackets.

148
00:11:59,700 --> 00:12:02,160
You can actually augment those if you only have one line.

149
00:12:02,850 --> 00:12:11,850
So what I'm going to do is say, just return the reference this for this object, right?

150
00:12:14,220 --> 00:12:18,510
So if that's the case, then we're just going to return this.

151
00:12:23,130 --> 00:12:24,000
So.

152
00:12:25,530 --> 00:12:34,440
Then what we're going to do, I guess, is otherwise we will return the money or return the object.

153
00:12:36,260 --> 00:12:43,040
So, in fact, you know, I guess we could kind of change this around because we're just going to return

154
00:12:44,720 --> 00:12:47,180
this if the.

155
00:12:49,860 --> 00:12:57,360
Object, if if this one is not bigger, because if it's if it's not, if this is not true right here.

156
00:12:58,600 --> 00:13:03,280
They're not the same model like you're trying to add something else to the called upon object, like

157
00:13:03,280 --> 00:13:03,910
the left hand side.

158
00:13:04,420 --> 00:13:07,330
We're just going to return the car we already have.

159
00:13:08,950 --> 00:13:12,820
So what we should do is we actually just add to this, I don't even need to put this in here.

160
00:13:13,180 --> 00:13:24,490
We can basically take this and kind of flip it around like we could say that this one is a less than

161
00:13:24,490 --> 00:13:26,320
or equal to which I really should like.

162
00:13:26,470 --> 00:13:28,810
I think it's more sensible to put this on the other side.

163
00:13:30,250 --> 00:13:31,360
So I'll copy that.

164
00:13:32,470 --> 00:13:37,690
And then we'll just kind of put that here, and we'll just say that this is greater than or equal to

165
00:13:37,690 --> 00:13:38,050
it, right?

166
00:13:38,710 --> 00:13:42,610
If the object is greater than or equal to it, then we can return the object.

167
00:13:44,410 --> 00:13:53,290
But I can literally put this all kind of inside of here and just have one big, long thing, so I can

168
00:13:53,290 --> 00:13:59,770
say so that, you know, the models, the saying the brand is the same and the object is bigger, then

169
00:13:59,770 --> 00:14:02,920
we'll take that bigger object like otherwise we're not going to.

170
00:14:04,000 --> 00:14:10,540
So I can put that whole thing there and then all then I can have just one if and if that's the case

171
00:14:10,540 --> 00:14:15,280
and then censuses is only have one line here, you don't even need these brackets.

172
00:14:15,700 --> 00:14:19,990
I can just in and I can just say return object.

173
00:14:21,790 --> 00:14:24,190
Otherwise, we're just going to return our same car.

174
00:14:27,130 --> 00:14:27,550
So.

175
00:14:29,070 --> 00:14:35,700
What we're seeing here is we're saying, OK, well, if the model, if the model of both of the car

176
00:14:35,700 --> 00:14:40,860
is being added together the same and the brand of both cars being added together are the same.

177
00:14:41,310 --> 00:14:42,090
And.

178
00:14:43,300 --> 00:14:51,970
The thing that we're trying to add to the left hand side is greater has a greater upgrade, codes like

179
00:14:51,970 --> 00:14:54,040
size, there's more upgrades in that.

180
00:14:54,550 --> 00:15:01,960
Then we're going to go ahead and return the object that we're adding because it has more upgrades and

181
00:15:01,960 --> 00:15:02,680
we want that.

182
00:15:02,680 --> 00:15:07,830
Like if if we have a Ford Fiesta that has more upgrades, then we want that one, right?

183
00:15:08,050 --> 00:15:09,700
Otherwise we're just going to give back.

184
00:15:12,470 --> 00:15:18,680
The same thing, so we're going to end up having the same car and we're not going to do an upgrade,

185
00:15:18,680 --> 00:15:19,340
basically.

186
00:15:20,970 --> 00:15:25,950
So, you know, not like the most cynical plus operator, but the thing is, is that you could put whatever

187
00:15:25,950 --> 00:15:32,280
you want in here, you could and you could go through and make the union of those two vectors.

188
00:15:33,600 --> 00:15:37,620
I'm just not going to do that because I don't want to make something that's too missing detracts from

189
00:15:37,620 --> 00:15:37,890
that.

190
00:15:38,390 --> 00:15:43,980
You know, when we have like the foreigners and all that stuff, I just want to focus on the operator.

191
00:15:46,920 --> 00:15:51,510
You know, or you could just leave it like this, or you could just think of and let's see, you can

192
00:15:51,540 --> 00:15:52,530
make like.

193
00:15:55,470 --> 00:16:00,330
Maybe you just make some new upgrade thing where you like kind of.

194
00:16:02,060 --> 00:16:07,400
Morph the upgrade codes together and come up with new upgrades, I don't know it can really be whatever

195
00:16:07,400 --> 00:16:07,820
you want.

196
00:16:08,090 --> 00:16:13,340
The point is that you are the one deciding what the behavior of this operator is now.

197
00:16:13,340 --> 00:16:20,120
And what's cool is that you can now use plus minus times, you know, which is multiply.

198
00:16:20,230 --> 00:16:27,170
So I mean, to decide what happens with your objects, right, you're able to use simple operators now.

199
00:16:27,170 --> 00:16:39,320
You don't have to have a function that says, like, you know, like car or car, find which car is

200
00:16:39,320 --> 00:16:43,940
like better upgrade and return.

201
00:16:43,940 --> 00:16:46,520
You know, I'm being kind of ridiculous with like that function.

202
00:16:48,020 --> 00:16:53,270
But you'd have to like, make your own function that did this and then you take the concept car object

203
00:16:53,270 --> 00:16:58,130
and then like, you'd have to go to Maine and you have to call that function here, right?

204
00:16:58,130 --> 00:17:04,610
And pass this other car like, you know, pass one car to it and then decide and then it would return

205
00:17:04,610 --> 00:17:05,930
it and then you could save it.

206
00:17:06,200 --> 00:17:09,200
You'd have to be like car to dot that function pass car four.

207
00:17:09,500 --> 00:17:10,490
You don't have to do all that.

208
00:17:10,490 --> 00:17:15,860
You can just literally say, like, Oh, this is the behavior I want when someone tries to add these

209
00:17:15,860 --> 00:17:17,480
cars that I created together.

210
00:17:18,350 --> 00:17:18,630
Right?

211
00:17:18,650 --> 00:17:20,420
So that's what makes it really powerful.

212
00:17:20,990 --> 00:17:25,810
Over the operators makes it nice for the end user on the client side.

213
00:17:25,820 --> 00:17:29,950
Like make using your library, lets see you create some kind of code library.

214
00:17:29,960 --> 00:17:34,610
Someone can import it up here like, Oh, I'm going to import car that age and then now I get to add

215
00:17:34,610 --> 00:17:35,360
cars together.

216
00:17:35,390 --> 00:17:35,780
Cool.

217
00:17:36,740 --> 00:17:41,150
So that's why it's pretty powerful, and that's the point of us learning about this stuff.

218
00:17:42,360 --> 00:17:43,070
So.

219
00:17:44,920 --> 00:17:46,450
Yeah, I think that should be fine.

220
00:17:47,770 --> 00:17:49,960
So, yeah, I'm just going to leave it at this.

221
00:17:51,820 --> 00:17:55,030
You know, we could also make some sort of.

222
00:17:56,720 --> 00:18:01,340
Minus operator, you know, I might as well make that since this kind of simple like we could make something

223
00:18:01,340 --> 00:18:04,400
that's flipped where it just gives us back the smaller car.

224
00:18:04,910 --> 00:18:08,000
So let's go over here and do that as well.

225
00:18:08,300 --> 00:18:10,940
I was only going to do the class operator, but we can do minus two.

226
00:18:11,690 --> 00:18:13,160
You then it's pretty much the same.

227
00:18:14,880 --> 00:18:19,080
We'll cost car and object in the header file.

228
00:18:19,100 --> 00:18:30,800
We'll go over here and we'll just put this car car operator and no operator minus

229
00:18:36,140 --> 00:18:36,590
cool.

230
00:18:37,610 --> 00:18:40,370
And so we'll pretty much have the same exact thing.

231
00:18:41,030 --> 00:18:47,120
So I'm just going to copy paste this and then we can just flip it around so that we still want it to

232
00:18:47,120 --> 00:18:50,960
be the same model and make probably modern brands sorry.

233
00:18:51,710 --> 00:19:00,620
But what we want is to see if it's less than right, if it's less than.

234
00:19:01,620 --> 00:19:02,820
Then maybe we will.

235
00:19:05,020 --> 00:19:09,820
And this one, we should probably just say greater than right now equal to you, because if it's equal

236
00:19:09,820 --> 00:19:16,870
to, then we will just, uh, return the same car because we have no interest if it has the same amount

237
00:19:16,870 --> 00:19:17,650
of upgrades, right?

238
00:19:18,190 --> 00:19:21,660
So we'll say this is the less that in this is greater than it's pretty much the same thing.

239
00:19:21,670 --> 00:19:25,540
So now we can subtract them and we'll get the kind of worst car.

240
00:19:25,540 --> 00:19:28,320
I guess we get the smaller amount of upgrades from it.

241
00:19:28,330 --> 00:19:30,210
Maybe we want like a cheaper car, right?

242
00:19:30,220 --> 00:19:32,800
We don't want so many, so many upgrades.

243
00:19:33,730 --> 00:19:39,880
So, you know, because maybe like this would could hypothetically increase the price or something.

244
00:19:39,880 --> 00:19:45,400
If you have more upgrades, which we're not doing that right now, you know, if we go up here, we

245
00:19:45,400 --> 00:19:48,490
don't really have a price here, but we could change that if we wanted to.

246
00:19:49,360 --> 00:19:49,720
Cool.

247
00:19:49,730 --> 00:19:52,360
So let's go ahead and test this out.

248
00:19:53,640 --> 00:20:01,920
So I might actually do a little minus two, so we'll say showing car for upgrades below and then maybe

249
00:20:01,920 --> 00:20:08,010
what we'll do is we'll say, you know, car for equals.

250
00:20:09,180 --> 00:20:09,930
Let's see.

251
00:20:10,560 --> 00:20:22,350
Uh, let's just say, I guess we'd have to make kind of a new a new car so maybe I can make like a car

252
00:20:22,350 --> 00:20:23,310
five or something.

253
00:20:23,320 --> 00:20:24,060
So car.

254
00:20:24,090 --> 00:20:25,950
Car five.

255
00:20:30,730 --> 00:20:37,570
Let's just say car car five, and we'll just say this is also white Ford Fiesta.

256
00:20:38,810 --> 00:20:46,400
So why don't I put that here, and we'll just say, we'll say it's a white Ford Fiesta, but actually

257
00:20:46,490 --> 00:20:49,010
we can just, you know, it can just be the same make and model.

258
00:20:49,010 --> 00:20:55,040
So we can just say this is blue Ford Fiesta with a hundred miles or something.

259
00:20:55,700 --> 00:21:02,930
So now what I could do is I could say, you know, I could say car five equals.

260
00:21:05,240 --> 00:21:13,940
Let's say, let's add some upgrades to, let's say, car five and upgrade and we'll just say like five

261
00:21:13,940 --> 00:21:14,960
or something like that.

262
00:21:15,320 --> 00:21:18,530
And then we'll say car five equals.

263
00:21:21,500 --> 00:21:24,200
We'll say car four equals.

264
00:21:26,230 --> 00:21:32,110
Car five or say, like car Ford minus car five.

265
00:21:34,870 --> 00:21:38,050
Something like that, and then we'll just say.

266
00:21:42,700 --> 00:21:50,150
I can say this again, I'll just copy this, so I'll just say car showing car for upgrades below, and

267
00:21:50,150 --> 00:21:51,440
then we'll just say.

268
00:21:54,400 --> 00:21:58,030
Car for Dodge show upgrades.

269
00:22:00,970 --> 00:22:05,890
This will show other upgrades there, so I can go ahead and comment this now, so.

270
00:22:07,020 --> 00:22:13,590
We have this section here where I kind of like add a show upgrades for card for just to show you what

271
00:22:13,590 --> 00:22:15,120
the default is from it.

272
00:22:15,120 --> 00:22:21,300
Being set to car to car two doesn't have any upgrades, so it should just have one, right because they

273
00:22:21,300 --> 00:22:26,400
come by default with one upgrade push back one, right?

274
00:22:26,400 --> 00:22:31,080
So when you make a new car, it just pushes back one for the constructors here.

275
00:22:33,560 --> 00:22:37,940
So it'll have one when we show the upgrade, then we're going to add two and four two car two.

276
00:22:38,660 --> 00:22:41,840
Then we'll show cartoons upgrade and should say one, two and four.

277
00:22:42,800 --> 00:22:47,090
Then what we'll do is we'll say we'll do this.

278
00:22:47,090 --> 00:22:50,420
Plus we'll say Car four is equal to car two plus car for it.

279
00:22:50,630 --> 00:22:53,750
And we know what's going to happen is since Car two has more.

280
00:22:54,840 --> 00:23:00,990
Upgrades now it has more upgrades than car for it's going to return back to us, car to you and we're

281
00:23:00,990 --> 00:23:07,920
going to say car four is now going to be having the same upgrades as Car four, so we're going to make

282
00:23:07,920 --> 00:23:08,520
it a new car.

283
00:23:08,530 --> 00:23:14,250
It's not just going to be the same upgrades, it's just going to totally replace with this car.

284
00:23:14,660 --> 00:23:18,750
You know, it's going to take everything about cartoon put in here because of our assignment operator

285
00:23:19,710 --> 00:23:24,900
so that once will show the upgrades and CAR four should have one, two and four for the upgrades.

286
00:23:26,000 --> 00:23:29,840
We'll make this car fire that has a grade five, and then what we'll do is we'll subtract it and we

287
00:23:29,840 --> 00:23:33,410
should have car fire then get stored in car for because it's less right.

288
00:23:34,490 --> 00:23:37,800
So let's go ahead and see if that is how it behaves.

289
00:23:37,800 --> 00:23:42,170
So I'm going to save these files I could use to save all, actually.

290
00:23:44,800 --> 00:23:45,490
So.

291
00:23:47,500 --> 00:23:49,900
I mean, see, I don't think this has.

292
00:23:49,930 --> 00:23:51,430
Oh yeah, that has an error right there.

293
00:23:51,940 --> 00:23:54,190
So let's go ahead and save that too.

294
00:23:55,720 --> 00:23:58,150
So I'm going to go ahead and.

295
00:24:02,360 --> 00:24:08,450
Compile this, so I think it yeah, it doesn't like the unsigned injury comparison to when I was compiling

296
00:24:08,450 --> 00:24:10,590
it before I.

297
00:24:11,630 --> 00:24:14,580
I think that's not something that we need to worry about now.

298
00:24:17,240 --> 00:24:23,030
So I'm just going to do I'm actually just going to compile and here I'm going to do G Plus Plus and

299
00:24:23,360 --> 00:24:24,650
just do star.

300
00:24:24,830 --> 00:24:30,320
So all of that seeps because we want to compile co-recipient.

301
00:24:30,320 --> 00:24:31,250
Mean may not be.

302
00:24:31,640 --> 00:24:35,020
And when I say that show, and I'm just going to call this mean that you see.

303
00:24:37,920 --> 00:24:40,050
OK, so.

304
00:24:42,630 --> 00:24:46,650
OK, so I'm returning the cons, Jeffrey, and so let's go ahead and make this.

305
00:24:49,990 --> 00:24:53,870
Let's go ahead and make the speedy.

306
00:24:57,470 --> 00:25:00,950
Owners can change to non-conscious now, we can also make this return a cost.

307
00:25:05,050 --> 00:25:08,740
But where am I at?

308
00:25:11,360 --> 00:25:11,780
Here we go.

309
00:25:13,040 --> 00:25:19,040
So this is a common story, and so we're returning to here, even though we say that we don't return

310
00:25:19,050 --> 00:25:24,270
to, so we just do cars, so there could still be problems with this in Maine if I'm returning like

311
00:25:24,800 --> 00:25:29,510
a constant to it because ideally what we do is make a new one.

312
00:25:29,510 --> 00:25:31,610
So why don't we just make like A.?

313
00:25:34,130 --> 00:25:35,630
We can make a new car, right?

314
00:25:35,870 --> 00:25:37,130
So we'll keep it.

315
00:25:37,130 --> 00:25:43,140
Cons But what I'll say is I'll just say I'll make I'll do a smart point.

316
00:25:43,160 --> 00:25:46,310
And what if we do that with same type car smart pointer?

317
00:25:46,310 --> 00:25:56,660
And I'll just say new car and it'll be a new type of car and we will just say that.

318
00:26:01,850 --> 00:26:04,700
It'll be we'll use the assignment operator, how about that?

319
00:26:05,120 --> 00:26:06,470
So I'm going to put this here.

320
00:26:07,570 --> 00:26:09,930
You put some brackets together, multiple lives now.

321
00:26:11,910 --> 00:26:19,500
And what I will do is I will just say that the new car so I'll do reference this and I'll say new car

322
00:26:21,540 --> 00:26:22,410
equals.

323
00:26:25,590 --> 00:26:32,090
Uh, oh, actually, you know what I can do, I can just make this.

324
00:26:36,720 --> 00:26:39,450
My to use the copy constructor, except it's going to be.

325
00:26:39,480 --> 00:26:40,020
Let's see.

326
00:26:40,890 --> 00:26:42,750
Yeah, that should work fine as a concert.

327
00:26:44,090 --> 00:26:49,400
Assured finest comments, so I have concert in there, so I can actually I should be able to do this,

328
00:26:49,400 --> 00:26:54,650
I think I should say new car equals object.

329
00:26:55,460 --> 00:26:57,980
So hopefully this will work.

330
00:27:00,120 --> 00:27:06,900
So let me see if I can copy this over this code over here, so I'm just how feeling like all this?

331
00:27:07,800 --> 00:27:11,400
Put it here and then of course, I'll just go and I'll flip the symbol, right?

332
00:27:16,100 --> 00:27:21,580
Flip the symbol there, and hopefully this will work fine.

333
00:27:24,560 --> 00:27:30,350
You know, the smart pointer here, well, of course, delegates also, I'd like to use that and then.

334
00:27:31,860 --> 00:27:38,850
We'll return these, right, so I'll just we'll just reference this and return new car.

335
00:27:44,340 --> 00:27:46,170
So let's see if we can get this to work.

336
00:27:51,160 --> 00:27:52,610
Don't know if it will, but.

337
00:27:53,150 --> 00:27:55,910
OK, so.

338
00:27:59,120 --> 00:28:03,080
And valid use of this in non-member function.

339
00:28:05,730 --> 00:28:07,060
One 18.

340
00:28:11,780 --> 00:28:13,790
Seen declared a prayer here.

341
00:28:15,650 --> 00:28:18,100
Brand was not declared in this.

342
00:28:19,920 --> 00:28:25,300
Sculpted, I have the scope resolution are there.

343
00:28:25,980 --> 00:28:27,390
This was lowercase.

344
00:28:28,050 --> 00:28:29,350
Sorry about that from there.

345
00:28:29,370 --> 00:28:33,390
Let's see if that works hard to Cassius employers.

346
00:28:36,860 --> 00:28:40,100
OK, so that seems to compile fine, sorry for the wait there.

347
00:28:40,760 --> 00:28:46,580
It's hard for me visually to see that I mean this lower case, so scope resolution was.

348
00:28:48,160 --> 00:28:50,740
Not resolved, and it was saying like, what are these things?

349
00:28:51,230 --> 00:28:58,330
It says you don't have access to this, you don't have access to this and this, you know, so yeah,

350
00:28:58,360 --> 00:28:59,410
now we should begin to go.

351
00:29:00,010 --> 00:29:01,840
So let's go ahead and run this.

352
00:29:03,900 --> 00:29:05,760
So let's see what it says here.

353
00:29:09,390 --> 00:29:13,590
So showing car upgrades below, so here let's go ahead and look at main.

354
00:29:16,080 --> 00:29:17,010
So we were saying.

355
00:29:18,440 --> 00:29:25,640
This should have won for Australia, so it shows one, then we add two and four to car two and we show

356
00:29:25,640 --> 00:29:28,700
cartoons upgrades and it should have one, two and four, which it shows.

357
00:29:30,820 --> 00:29:33,730
And then let's see.

358
00:29:39,010 --> 00:29:45,670
When those objects go out of scope and the local functions, it calls the destructor, so those are

359
00:29:45,670 --> 00:29:46,090
the.

360
00:29:47,330 --> 00:29:48,140
Smart pointer.

361
00:29:50,150 --> 00:29:53,090
And then let's see, we do.

362
00:29:54,810 --> 00:30:02,790
So, yeah, we all showed up, guys, here's the car two plus car four, so we're going to go in there

363
00:30:02,790 --> 00:30:05,910
and show a car for upgrades below.

364
00:30:06,450 --> 00:30:08,100
So we have one two four.

365
00:30:08,130 --> 00:30:08,460
Right?

366
00:30:08,700 --> 00:30:10,200
So a car for was this.

367
00:30:11,070 --> 00:30:16,860
Now it's having all of these upgrades because we chose the one that was bigger, right?

368
00:30:18,550 --> 00:30:24,910
So that's why right here is making this print out, these instructors are, I believe, because of the

369
00:30:24,910 --> 00:30:31,630
smart pointers going out of scope here to these local smart pointers that when they go out of scope,

370
00:30:31,630 --> 00:30:32,320
they are.

371
00:30:33,380 --> 00:30:36,920
Cleaned up, so, uh.

372
00:30:39,160 --> 00:30:42,550
Now we add upgrade to car five.

373
00:30:43,750 --> 00:30:47,080
Then we do a car for is now a car for minus car five.

374
00:30:49,640 --> 00:30:55,320
And so five should have one in five, right, and we noticed that when we now say showing car four of

375
00:30:55,340 --> 00:30:59,300
grades below again, it's now has just one and five, right?

376
00:30:59,750 --> 00:31:03,200
Because Car five had less upgrades than car for.

377
00:31:04,540 --> 00:31:09,340
OK, so I think that that is all that we're going to go over in this session.

378
00:31:10,270 --> 00:31:12,970
I'll talk more about the mathematical operators at some point.

379
00:31:13,510 --> 00:31:16,060
But pretty much they're all the same.

380
00:31:16,060 --> 00:31:18,330
We can decide the behavior for each one.

381
00:31:18,340 --> 00:31:22,090
You noticed that we were able to copy over everything from the plus to the minus, and you could do

382
00:31:22,090 --> 00:31:24,700
the same thing with the multiplication operator.

383
00:31:24,700 --> 00:31:29,980
You would just decide how you want the behavior of that to be as far as the code locally inside this

384
00:31:29,980 --> 00:31:30,400
function.

385
00:31:31,480 --> 00:31:31,750
All right.

386
00:31:31,750 --> 00:31:34,270
So with that, I will see you in the next lesson.
