1
00:00:01,460 --> 00:00:02,090
Hello everyone.

2
00:00:02,090 --> 00:00:05,270
So we have discussed about polymorphism in the last two videos.

3
00:00:05,270 --> 00:00:06,590
I hope that is clear now.

4
00:00:06,590 --> 00:00:09,920
And we have also started discussing about virtual functions.

5
00:00:09,920 --> 00:00:11,750
So what are ritual functions.

6
00:00:11,870 --> 00:00:16,720
So virtual functions are those functions that are present in the base class and they're overwritten

7
00:00:16,750 --> 00:00:18,390
in the derived classes.

8
00:00:18,410 --> 00:00:18,980
Okay.

9
00:00:18,980 --> 00:00:23,110
In this will do I want to discuss about pure virtual functions.

10
00:00:23,240 --> 00:00:26,890
Okay I want to discuss about pure virtual functions.

11
00:00:26,960 --> 00:00:29,030
So what are two or which functions.

12
00:00:29,030 --> 00:00:35,560
So beyond what dual functions are virtual functions but they do not have definitions.

13
00:00:36,140 --> 00:00:40,950
Okay so the functions that do not have a definition are called Pure virtual function.

14
00:00:41,000 --> 00:00:43,310
So what is the syntax for creating a function.

15
00:00:43,320 --> 00:00:49,760
Well tool so we will write the key word virtual and let's say we are talking about the print function

16
00:00:49,760 --> 00:00:51,490
of difficult class.

17
00:00:51,530 --> 00:00:59,030
So by writing the keyword by adding the keyword virtual this print function is now of virtual function.

18
00:00:59,030 --> 00:00:59,620
Okay.

19
00:00:59,670 --> 00:01:01,550
Now this is a normal virtual function.

20
00:01:01,550 --> 00:01:03,820
I want to create a pure virtual function.

21
00:01:03,950 --> 00:01:09,110
So the syntax for creating a pure virtual function is first of all we will write the keyword virtual

22
00:01:09,920 --> 00:01:13,430
then let's say I'm converting this function into pure which will function.

23
00:01:13,440 --> 00:01:19,700
So virtual white print and beyond what your function means they do not have definition.

24
00:01:19,700 --> 00:01:22,300
So it will not have definition.

25
00:01:22,310 --> 00:01:29,470
So this is the syntax for creating a pure virtual function okay.

26
00:01:29,590 --> 00:01:31,160
It will not have definition.

27
00:01:31,170 --> 00:01:32,470
Now the scene seeing good.

28
00:01:32,480 --> 00:01:35,950
Okay now let's.

29
00:01:35,970 --> 00:01:43,340
I'm coming despite so I want to create I want to convert this function and to pure virtual function.

30
00:01:43,340 --> 00:01:49,790
So we have to remove the definition I am removing the definition and then we do not have a definition.

31
00:01:49,790 --> 00:01:50,490
Okay.

32
00:01:50,810 --> 00:01:54,360
So this is pure virtual function no

33
00:02:01,050 --> 00:02:01,330
okay.

34
00:02:01,340 --> 00:02:06,680
So this is the syntax for creating a pillar which will function simply no definition at all.

35
00:02:06,680 --> 00:02:07,220
Okay.

36
00:02:07,340 --> 00:02:10,280
Now we will see in some time why we need to build a virtual function.

37
00:02:10,280 --> 00:02:12,500
What is the use case of build virtual function.

38
00:02:12,500 --> 00:02:17,150
But before we all virtual function let us talk about abstract classes okay.

39
00:02:17,210 --> 00:02:20,480
What types of classes and why do we need them.

40
00:02:21,380 --> 00:02:27,810
So let us first try to understand what that abstract classes okay.

41
00:02:27,870 --> 00:02:33,060
So if a class contain a pure virtual function then that class is an abstract class.

42
00:02:33,630 --> 00:02:34,090
Okay.

43
00:02:34,170 --> 00:02:40,730
So if a class contains a pure virtual function then that class will become abstract class.

44
00:02:40,740 --> 00:02:46,690
So here we call is an abstract class because it is containing a pool which will function.

45
00:02:46,770 --> 00:02:48,340
Okay simple.

46
00:02:48,390 --> 00:02:50,140
Now what is the meaning of abstract.

47
00:02:50,280 --> 00:02:53,770
So abstract means incomplete.

48
00:02:53,990 --> 00:02:57,800
Okay so this class is an incomplete class.

49
00:02:57,810 --> 00:03:04,310
Why is incomplete because it is having a function it contains a function that doesn't have definition.

50
00:03:04,310 --> 00:03:04,800
Okay.

51
00:03:04,880 --> 00:03:07,390
Now what is the purpose of abstract classes.

52
00:03:07,430 --> 00:03:14,250
So if a class is an abstract class then if you will try to create the object of the abstract class then

53
00:03:14,250 --> 00:03:15,690
you will get an error.

54
00:03:15,690 --> 00:03:16,160
Okay.

55
00:03:16,230 --> 00:03:19,990
So basically we cannot create object of abstract classes.

56
00:03:20,250 --> 00:03:22,500
Okay since we call is an abstract class.

57
00:03:22,530 --> 00:03:26,500
So if we will try to create the object of difficult class you will get an error.

58
00:03:26,700 --> 00:03:27,140
Okay.

59
00:03:27,240 --> 00:03:34,460
So if you will write we call v you will get an error and that it will be that we call class is an abstract

60
00:03:34,460 --> 00:03:38,390
class so you cannot create the object of the F classes.

61
00:03:38,390 --> 00:03:38,830
Okay.

62
00:03:38,960 --> 00:03:39,890
Now let's see called

63
00:03:43,340 --> 00:03:44,660
so let us come into everything

64
00:03:47,940 --> 00:03:48,150
okay.

65
00:03:48,170 --> 00:03:49,520
So we have only we call we.

66
00:03:49,590 --> 00:03:53,760
Okay now let us try to run this file so the output will be that we could class.

67
00:03:53,790 --> 00:03:56,340
We will get an error and that will be.

68
00:03:56,340 --> 00:04:03,980
So let's see that it so that it is because class is an abstract class and we cannot create the object

69
00:04:03,980 --> 00:04:05,620
of the abstract classes.

70
00:04:05,870 --> 00:04:06,340
Okay.

71
00:04:06,440 --> 00:04:07,530
Simple enough.

72
00:04:07,610 --> 00:04:15,870
Now there is one more thing that will happen since so this is we cut glass and we have a glass cut which

73
00:04:15,930 --> 00:04:20,460
in height from the we clicked glass we could Glass has now become an abstract glass because it contains

74
00:04:20,460 --> 00:04:21,630
a pure virtual function.

75
00:04:21,650 --> 00:04:22,210
Okay.

76
00:04:22,350 --> 00:04:22,890
No glass.

77
00:04:22,920 --> 00:04:27,220
God has two options glass God has two options.

78
00:04:27,220 --> 00:04:33,940
First option is that it will implement all the pure white gel function of the wickedness so implement

79
00:04:35,100 --> 00:04:43,800
all the pure virtual functions of difficult glass all pure virtual functions of because less.

80
00:04:44,010 --> 00:04:49,080
Okay now the second way the second option is it will not implement all pure white will function.

81
00:04:49,080 --> 00:04:53,880
So what will happen this glass car will become abstract glass.

82
00:04:54,060 --> 00:04:58,090
It will also become abstract glass okay.

83
00:04:58,820 --> 00:05:01,030
So Glass car has two options.

84
00:05:01,070 --> 00:05:06,380
First first option is implement all the power watch and function of the vehicle glass.

85
00:05:06,410 --> 00:05:12,260
Then in that case the glass car will become a normal glass and then we can create the object of the

86
00:05:12,260 --> 00:05:13,180
car glass.

87
00:05:13,190 --> 00:05:19,370
The second option is if it will not implement all the pillar which will function if it will not give

88
00:05:19,490 --> 00:05:21,710
the definition of purely virtual function.

89
00:05:21,710 --> 00:05:24,650
Then in that case it will become an abstract class.

90
00:05:24,770 --> 00:05:25,030
Okay.

91
00:05:25,040 --> 00:05:29,760
And we will not be able to create the object of the car class.

92
00:05:29,780 --> 00:05:35,750
Okay so in this case we can see here brain function is a pure virtual function and the class card is

93
00:05:35,750 --> 00:05:40,670
giving the definition of B all right dual function all the poor which is function of the vehicle class.

94
00:05:40,700 --> 00:05:43,910
So in this case this is a normal class.

95
00:05:43,920 --> 00:05:44,860
This is right.

96
00:05:45,060 --> 00:05:50,430
But if you will remove the print it will remove the implementation of the print function.

97
00:05:50,430 --> 00:05:57,270
Then the car C will throw this added value because it dies also become an abstract class incomplete

98
00:05:57,270 --> 00:05:57,900
class.

99
00:05:58,020 --> 00:06:01,660
Why it has become an abstract class because if will see the structure of the car.

100
00:06:01,670 --> 00:06:09,300
Class you can see very carefully that this is class got since this class got inherits from the vehicle

101
00:06:09,300 --> 00:06:17,640
class and we could class has a function has an incomplete function so the class card also has this incomplete

102
00:06:17,640 --> 00:06:18,200
function.

103
00:06:18,380 --> 00:06:18,970
Okay.

104
00:06:19,050 --> 00:06:21,720
This class card also has this incomplete function.

105
00:06:21,720 --> 00:06:26,760
The class is an abstract class also so we cannot create the object of the car class.

106
00:06:27,470 --> 00:06:27,980
Okay.

107
00:06:28,110 --> 00:06:31,880
Now let's see in code so.

108
00:06:32,660 --> 00:06:34,580
Okay so let's remove the definition

109
00:06:37,430 --> 00:06:38,290
since.

110
00:06:38,420 --> 00:06:46,300
Okay so first we have definition since we have a definition we can create the object of the car class.

111
00:06:46,330 --> 00:06:51,350
Okay so if we will write Ghazi then this is right.

112
00:06:51,430 --> 00:06:55,450
Okay so our goal will be working.

113
00:06:55,710 --> 00:06:56,720
So what code is working.

114
00:06:56,910 --> 00:06:57,470
Okay.

115
00:06:57,600 --> 00:07:01,070
Now if I will remove this print function.

116
00:07:01,350 --> 00:07:05,750
So this car class has also become and have class and this time it will run this file.

117
00:07:05,760 --> 00:07:06,740
We will get an added.

118
00:07:06,910 --> 00:07:12,620
Okay so we are getting an edit and let's see that it so the class card is an abstract class.

119
00:07:12,690 --> 00:07:13,100
Okay.

120
00:07:18,280 --> 00:07:18,510
Okay.

121
00:07:18,520 --> 00:07:24,350
So now we have understood what our what dual functions and what that abstract classes.

122
00:07:24,370 --> 00:07:25,390
Okay so one more thing.

123
00:07:25,390 --> 00:07:27,400
What are beautiful classes.

124
00:07:27,430 --> 00:07:34,550
Okay so there is something called pure abstract classes so we know where that abstract class there is

125
00:07:34,550 --> 00:07:42,230
something called pure abstract classes what are pure abstract classes.

126
00:07:42,230 --> 00:07:49,850
So since the vehicle we call is a beautiful class because it has only one function and that function

127
00:07:49,880 --> 00:07:52,330
is a pure function pure ritual function.

128
00:07:52,340 --> 00:07:59,750
Okay so pure abstract class means if an abstract class has all the functions as below what you'll function

129
00:08:01,850 --> 00:08:10,340
so all functions will be pure virtual then that class will be pure after class.

130
00:08:10,490 --> 00:08:10,950
Okay.

131
00:08:11,060 --> 00:08:12,300
So this vehicle.

132
00:08:12,770 --> 00:08:15,410
Okay so we have this we could class this vehicle.

133
00:08:15,410 --> 00:08:17,020
Class can have many functions.

134
00:08:17,030 --> 00:08:23,260
Okay let's say brain function and let's say getters and setters okay.

135
00:08:23,530 --> 00:08:27,160
So this brain function is a virtual build virtual function.

136
00:08:27,190 --> 00:08:27,390
Okay.

137
00:08:27,400 --> 00:08:29,690
So this this is a pure virtual function.

138
00:08:29,750 --> 00:08:34,170
Various trendsetter they have definitions so they are not pure virtual function.

139
00:08:34,180 --> 00:08:38,770
So in that case this class is only abstract class.

140
00:08:39,050 --> 00:08:44,990
We'll call this class only abstract class via abstract because it is containing a pure virtual function.

141
00:08:45,100 --> 00:08:49,360
But if the getters and setters they are also pure virtual okay.

142
00:08:49,360 --> 00:08:56,110
If I really make if I will remove the definition of Gordon setter I make them zero then this wicked

143
00:08:56,140 --> 00:09:00,330
class is containing all the functions as pure virtual functions.

144
00:09:00,330 --> 00:09:03,850
Then this abstract class will recall less during class.

145
00:09:04,120 --> 00:09:08,930
Okay so perfect class means all the function of the class will be pure virtual.

146
00:09:09,010 --> 00:09:11,320
Okay simple enough.

147
00:09:11,320 --> 00:09:15,790
Now we have understood the meaning of abstract classes and the pure virtual function.

148
00:09:15,790 --> 00:09:17,010
Now let's see the use case.

149
00:09:17,020 --> 00:09:19,130
Let's discuss about the use case.

150
00:09:19,180 --> 00:09:25,510
So in the last video we discussed we took an example of an employee an organization which want to give

151
00:09:25,510 --> 00:09:28,390
salary to the people and thus any form level were different.

152
00:09:28,390 --> 00:09:35,710
So they were for employees H.R. manager engineer and others.

153
00:09:35,710 --> 00:09:36,450
Okay.

154
00:09:36,670 --> 00:09:42,490
And what we did was we created an employee at a so this was off tape.

155
00:09:42,510 --> 00:09:51,410
Employee start this was of type employee style so the first index zero was pointing towards an object

156
00:09:51,410 --> 00:09:55,310
of H.R. plus then manager and then ingenious and others.

157
00:09:55,490 --> 00:09:55,810
Okay.

158
00:09:55,820 --> 00:10:02,750
And then we related over this area and then we did then inside the loop we did something like this.

159
00:10:02,770 --> 00:10:05,180
E to calculate salary function.

160
00:10:05,210 --> 00:10:12,470
OK we are calling the calculate salary function but with the help of e we can only access we can only

161
00:10:12,470 --> 00:10:16,310
access the properties of the Employee class that is the base class.

162
00:10:16,310 --> 00:10:20,510
We can only access the properties of the Employee class only the base class.

163
00:10:20,540 --> 00:10:27,590
So that's why we have to create a calculate salary function inside the Employee class and that function

164
00:10:27,590 --> 00:10:29,860
was virtually okay.

165
00:10:29,960 --> 00:10:30,170
Why.

166
00:10:30,170 --> 00:10:35,030
Well just because we have to decided the right time that which function to be called.

167
00:10:35,030 --> 00:10:35,290
Okay.

168
00:10:35,300 --> 00:10:37,280
So everything was working fine.

169
00:10:37,490 --> 00:10:37,720
Okay.

170
00:10:37,730 --> 00:10:38,470
So we cleared it.

171
00:10:38,500 --> 00:10:43,450
Because we're still functioning inside the Employee class and that function was well still function.

172
00:10:43,520 --> 00:10:44,120
Okay.

173
00:10:44,360 --> 00:10:50,570
So everything was fine but I want to what I want to say here is now this calculate salary function should

174
00:10:50,570 --> 00:10:58,250
be a pure virtual function not only what it should be pure virtual okay why pure virtual because I cannot

175
00:10:58,250 --> 00:11:03,560
decide what will be the salary inside the Employee class how can I give the definition of conclude salary

176
00:11:03,560 --> 00:11:04,280
function.

177
00:11:04,280 --> 00:11:07,400
Okay I cannot give the definition of calculate salary function.

178
00:11:07,400 --> 00:11:13,510
Okay so since I cannot give the definition what I will do I will make this function as pure virtual

179
00:11:13,550 --> 00:11:15,180
function.

180
00:11:15,370 --> 00:11:15,860
Okay.

181
00:11:15,910 --> 00:11:22,670
Since this function has become the pure virtual function we cannot create our object of type employee.

182
00:11:22,750 --> 00:11:28,600
Okay we can create we what we have to do we have to create a new class if we want to add another member.

183
00:11:29,050 --> 00:11:34,740
Okay let's say any other member new stuff or something.

184
00:11:34,950 --> 00:11:39,940
Okay so this is the use case of pure virtual function.

185
00:11:39,960 --> 00:11:45,810
There is one modulus case for example if we want to force a child class to implement the function.

186
00:11:45,900 --> 00:11:48,120
Okay so what do you want to do.

187
00:11:48,120 --> 00:11:51,720
I have a child class and I want their child class.

188
00:11:51,960 --> 00:11:57,870
I have a child class and I want that child class to implement a particular function.

189
00:11:57,870 --> 00:12:04,200
I want to force the child class to implement a particular function what I will do so inside the inside

190
00:12:04,200 --> 00:12:09,440
the base class I will make this function as pure what will function.

191
00:12:09,480 --> 00:12:14,690
Okay so that the child the class will be enforced to implement their definition of disputed virtual

192
00:12:14,730 --> 00:12:19,060
function otherwise the child's class will become the abstract class okay.

193
00:12:21,640 --> 00:12:28,820
So you can take one more example of how the pure module function can be used for example I have an animal

194
00:12:28,870 --> 00:12:30,360
class inside the animal.

195
00:12:31,240 --> 00:12:35,760
We have like Tiger cow hooves.

196
00:12:35,760 --> 00:12:36,370
Exactly.

197
00:12:36,810 --> 00:12:38,750
So this animal class has a function.

198
00:12:38,760 --> 00:12:40,470
Let's say you'd function.

199
00:12:40,470 --> 00:12:40,980
Okay.

200
00:12:41,040 --> 00:12:44,100
And the Tiger go and hose.

201
00:12:44,100 --> 00:12:44,470
Okay.

202
00:12:44,610 --> 00:12:45,490
They will have the.

203
00:12:45,750 --> 00:12:46,800
You'd function.

204
00:12:46,800 --> 00:12:50,760
So what we can do we can make this you'd function as pure virtual.

205
00:12:50,910 --> 00:12:56,100
Okay because it cannot give their definition of you'd function inside the animal class.

206
00:12:56,190 --> 00:13:02,820
So we will make this eat function as pure module function in this way the tiger class it will have it

207
00:13:02,880 --> 00:13:07,980
on its function it will give the definition of its own function call will give the definition of its

208
00:13:07,980 --> 00:13:12,140
own function and the horse will give the definition of its own function.

209
00:13:12,150 --> 00:13:15,960
Okay so this is the use case of build which will function.

210
00:13:15,960 --> 00:13:18,600
Okay so I hope everything is clear.

211
00:13:18,610 --> 00:13:20,460
No thank you.
