1
00:00:00,150 --> 00:00:00,450
OK.

2
00:00:00,480 --> 00:00:06,390
Welcome back to another lecture in this lecture, we're going to continue on talking about object oriented

3
00:00:06,390 --> 00:00:11,110
programming, and we're going to actually continue on with this car class using as an example.

4
00:00:11,130 --> 00:00:19,230
So this lecture will have two new kind of concepts or sub concepts within the realm of classes and object

5
00:00:19,230 --> 00:00:20,880
oriented programming that we're going to go over.

6
00:00:21,330 --> 00:00:26,040
And the first one that we're going to talk about is something that's not a huge topic, but I want to

7
00:00:26,040 --> 00:00:29,100
mention it, and that is something called CONT-.

8
00:00:29,100 --> 00:00:33,540
You might have seen this already and already know what concept means, but just in case I'm going to

9
00:00:33,540 --> 00:00:37,530
go ahead and go over it and also tell you how it pertains to functions.

10
00:00:38,310 --> 00:00:42,540
So you might have seen something like this as a constant, then a variable type.

11
00:00:42,570 --> 00:00:42,840
Right?

12
00:00:43,080 --> 00:00:44,010
Sorry, a data type.

13
00:00:45,000 --> 00:00:51,000
And then we have a variable name and something like this where it says contact and and it really can

14
00:00:51,000 --> 00:00:52,130
be any data type.

15
00:00:52,140 --> 00:00:54,370
And then we say, here's the variable name calling.

16
00:00:54,400 --> 00:00:56,100
I won and we say it's five.

17
00:00:56,580 --> 00:00:58,920
The word con stands for a constant.

18
00:00:59,460 --> 00:01:05,370
And what it means is that this integer I one should always remain five.

19
00:01:05,370 --> 00:01:07,890
It should be basically read only after that.

20
00:01:07,890 --> 00:01:09,000
We can print it out.

21
00:01:09,000 --> 00:01:12,090
We can see what it is, but we should not make changes to it.

22
00:01:12,720 --> 00:01:19,890
So if I was to try something like this and I say I equals seven, let me go ahead and save this and

23
00:01:19,890 --> 00:01:22,170
I'm going to compile it in here.

24
00:01:22,420 --> 00:01:27,080
Let's say G Plus plus R.S.V.P. Dash.

25
00:01:27,120 --> 00:01:28,680
Oh, card out

26
00:01:31,560 --> 00:01:33,510
and notice that it gives me an error rate here.

27
00:01:33,510 --> 00:01:39,000
So it says assignment is this error assignment of read only variable i1.

28
00:01:39,180 --> 00:01:44,850
So it's telling us that this i1 is really only it's really read only we're not allowed to modify it

29
00:01:44,850 --> 00:01:45,000
yet.

30
00:01:45,000 --> 00:01:50,400
We tried to modify it here on Line sixty eight and this can be anything like I could have this piece,

31
00:01:50,940 --> 00:01:53,790
you know, constant flow and it could be five point seven.

32
00:01:53,790 --> 00:01:57,960
And then here I just try and change it to like 7.9 or something like that.

33
00:01:58,290 --> 00:02:00,270
It still is not going to work.

34
00:02:00,720 --> 00:02:05,370
It's going to yell at me and say it's still in assignment of re, the only variable I won.

35
00:02:07,050 --> 00:02:08,460
So that's what constant means.

36
00:02:08,460 --> 00:02:09,870
And why would you use constants?

37
00:02:09,870 --> 00:02:14,550
Well, sometimes they're a little more efficient, you know, with compilation and all that stuff,

38
00:02:14,550 --> 00:02:18,210
because it's just knowing that this is going to remain the same.

39
00:02:18,210 --> 00:02:23,940
The whole time kind of makes everything a little more optimal.

40
00:02:23,940 --> 00:02:26,040
So they're useful.

41
00:02:26,040 --> 00:02:31,170
If you can make something konst and you know that it's not going to change, then it might be a good

42
00:02:31,170 --> 00:02:32,400
idea to make it constant.

43
00:02:32,730 --> 00:02:35,850
But so that's kind of a little recap, if you might have seen that before.

44
00:02:35,850 --> 00:02:42,300
If not, now you know what cost is as far as basic variables and data types and stuff like that, so

45
00:02:42,300 --> 00:02:43,890
you can make pretty much any type.

46
00:02:44,040 --> 00:02:48,840
This can be anything here, this highlighted section, and you can put a cost in front of it.

47
00:02:50,430 --> 00:02:54,540
So it also can be used with functions.

48
00:02:54,720 --> 00:03:00,900
And what I mean by that is that when you put context after a function like, for example, I can say

49
00:03:01,170 --> 00:03:03,690
and get odometer cards.

50
00:03:04,680 --> 00:03:07,260
So this is our member functions area, remember?

51
00:03:08,010 --> 00:03:10,830
So what I'm doing here is I'm putting this contest.

52
00:03:11,040 --> 00:03:14,730
And this is the prototype that means I also need to put it down here.

53
00:03:15,940 --> 00:03:21,250
So we have get odometer, and I would need to also put a concert right here after the parentheses,

54
00:03:21,250 --> 00:03:23,680
just like I did up here.

55
00:03:24,160 --> 00:03:32,950
What it means is that if we put this here, it's saying that this function is not going to modify the

56
00:03:32,950 --> 00:03:37,420
data of the object that is calling the function.

57
00:03:38,350 --> 00:03:40,990
And what is the object that's calling the function?

58
00:03:41,020 --> 00:03:42,370
Well, let's look at an example.

59
00:03:42,370 --> 00:03:45,340
We made a car object in a car to object, right?

60
00:03:45,580 --> 00:03:46,240
Let's take it.

61
00:03:46,510 --> 00:03:48,250
Let's take a look at car for an example.

62
00:03:48,260 --> 00:03:52,420
So here we have car dot, get odometer.

63
00:03:52,660 --> 00:03:57,670
This is the function get odometer being called on.

64
00:03:57,670 --> 00:04:02,140
And I say on because there's the dot, it's car dot yet odometer.

65
00:04:02,470 --> 00:04:06,400
So get odometer function is being called on car.

66
00:04:06,640 --> 00:04:08,260
So let's go back up here.

67
00:04:08,500 --> 00:04:18,160
What I was saying previously is that Konst means that the function get odometer should not modify the

68
00:04:18,160 --> 00:04:27,130
data of car in this example, and it doesn't write it's a getter or what we would call an accessory,

69
00:04:27,130 --> 00:04:27,460
right?

70
00:04:27,880 --> 00:04:29,830
It's not a mutineer or setter.

71
00:04:30,840 --> 00:04:38,010
It really just gives us the value of odometer, it's not changing anything, it's just giving us back

72
00:04:38,010 --> 00:04:39,330
whatever stored in odometer.

73
00:04:39,330 --> 00:04:44,490
So this is something that's totally fine and I can go ahead and say this and run this, and you notice

74
00:04:44,490 --> 00:04:46,650
that we don't get any error if I compile it.

75
00:04:48,230 --> 00:04:52,690
What if I was to put a cost on something else that does modify it, let's see what happens.

76
00:04:52,730 --> 00:04:57,800
So I go ahead and I put cost here and I say, Oh, that pain is not going to change anything, I promise.

77
00:04:57,800 --> 00:05:02,420
And then I'll go down here and I'll say, OK, let's go ahead and cut the cost on here.

78
00:05:02,420 --> 00:05:03,320
So it matches.

79
00:05:03,980 --> 00:05:06,410
And then I say this, I go ahead and.

80
00:05:09,250 --> 00:05:09,940
Compile it.

81
00:05:10,270 --> 00:05:13,900
Oh, look at this, we have some errors, so what do these errors say?

82
00:05:14,850 --> 00:05:20,340
Well, you notice that it's actually yelling at this, yelling at us for this code right here.

83
00:05:20,380 --> 00:05:22,230
Where is this paint color equals color?

84
00:05:22,650 --> 00:05:30,180
It says passing constant string as this argument desk discards qualifiers.

85
00:05:31,020 --> 00:05:36,690
This is a kind of a fancy, complicated way of just saying that, hey, you said you weren't going to

86
00:05:36,690 --> 00:05:43,740
change any of the data that has to do with the calling object and calling object is actually referred

87
00:05:43,740 --> 00:05:48,060
to as this like literally the word this.

88
00:05:48,510 --> 00:05:50,490
That's why it's here in the air and the arrow.

89
00:05:51,180 --> 00:05:57,090
So that calling object, we were not supposed to change its data and we said we wouldn't.

90
00:05:57,090 --> 00:06:00,930
Yet right here, compilers noticing that that is what we are doing.

91
00:06:00,930 --> 00:06:02,190
Painkiller equals color.

92
00:06:02,280 --> 00:06:06,810
So that is an issue and we cannot have that.

93
00:06:06,810 --> 00:06:09,060
So we're going to have to take this out now.

94
00:06:09,240 --> 00:06:16,320
You don't want to put a cost on anything that is changing the data because that is not a conscious for

95
00:06:17,340 --> 00:06:20,010
it's for something that doesn't change the data, right?

96
00:06:20,640 --> 00:06:26,880
So we can put it here because it just returns odometer and it's always just going to return odometer.

97
00:06:27,420 --> 00:06:28,380
And it's totally fine.

98
00:06:28,380 --> 00:06:34,200
If we were to like, modify odometer like later on, like, I could make some function here.

99
00:06:36,240 --> 00:06:44,610
I could say like and said Odometer, and I'm not going to make this cost.

100
00:06:46,780 --> 00:06:48,610
Let's go ahead and just say it.

101
00:06:53,080 --> 00:07:00,070
And it's going to call a reset or something, so we can say with this, get a whole another thing here

102
00:07:00,080 --> 00:07:08,320
that so we don't want to return it and say this will be void and then I'll go down here and we'll just

103
00:07:08,320 --> 00:07:12,100
say boy car sets odometer.

104
00:07:12,610 --> 00:07:14,910
And here was an reset.

105
00:07:15,160 --> 00:07:16,690
That's what we're going to reset it to.

106
00:07:16,990 --> 00:07:21,640
And we just say odometer equals reset.

107
00:07:23,200 --> 00:07:24,970
So I could do something like that.

108
00:07:24,970 --> 00:07:27,640
And let's just say we call get odometer.

109
00:07:27,640 --> 00:07:32,440
And then maybe here I'll send you a car set odometer.

110
00:07:32,710 --> 00:07:37,360
And I just say like eight hundred thirty seven or something like that.

111
00:07:37,900 --> 00:07:47,020
And then we go down here and we also say, car, it will get odometer.

112
00:07:51,850 --> 00:07:54,580
OK, so.

113
00:07:55,880 --> 00:08:00,320
Now I'm showing you that I have a set of downers, so we are changing the odometer value, right?

114
00:08:00,350 --> 00:08:04,010
So we said that this was constantly get odometer.

115
00:08:04,370 --> 00:08:08,500
Yeah, I'm changing it in this other function, but let's see what happens.

116
00:08:11,210 --> 00:08:17,810
So go ahead and compile it, and it gives a little bit about this, so it says it does not match any

117
00:08:17,810 --> 00:08:18,290
class.

118
00:08:19,130 --> 00:08:20,510
That is because.

119
00:08:23,090 --> 00:08:26,840
I did set paint.

120
00:08:28,940 --> 00:08:31,040
I think I put a constant road to tears.

121
00:08:31,710 --> 00:08:32,630
So.

122
00:08:39,580 --> 00:08:41,410
Oh, yeah, I this is so.

123
00:08:42,210 --> 00:08:43,810
So let's go ahead and save this.

124
00:08:47,380 --> 00:08:47,770
All right.

125
00:08:48,100 --> 00:08:50,440
So compile again, and it's fine, and why is it fine?

126
00:08:50,740 --> 00:08:57,850
It's fine because we are not saying that, said Odometer is concerned this would be a problem, right?

127
00:08:58,270 --> 00:09:00,160
But we're just saying that get odometer.

128
00:09:00,490 --> 00:09:07,090
So we're saying that this function specifically is not going to change any data like it's not going

129
00:09:07,090 --> 00:09:09,880
to change odometer or any other data, for that matter.

130
00:09:11,140 --> 00:09:12,120
This one is changing.

131
00:09:12,120 --> 00:09:13,270
And so we're not going to put const.

132
00:09:14,290 --> 00:09:16,250
So just wanted to introduce that.

133
00:09:16,250 --> 00:09:20,650
That's kind of the first thing I wanted to show you was concert in general and then cars being used

134
00:09:20,650 --> 00:09:22,540
with member functions of a class.

135
00:09:24,020 --> 00:09:25,680
So the next thing that we're going to go.
