1
00:00:01,780 --> 00:00:02,440
Hello everyone.

2
00:00:02,440 --> 00:00:06,160
So in the last video we discussed about different types of inheritance.

3
00:00:06,220 --> 00:00:06,660
Okay.

4
00:00:06,700 --> 00:00:10,350
In this video we will discuss about the fifth type.

5
00:00:10,600 --> 00:00:16,060
So in this ruling we will discuss about the fifth type of inheritance which is the hybrid inheritance.

6
00:00:16,060 --> 00:00:17,200
So what is the meaning of hybrid.

7
00:00:17,200 --> 00:00:18,690
Hybrid means mix.

8
00:00:18,700 --> 00:00:18,970
OK.

9
00:00:19,000 --> 00:00:24,970
So in order to achieve hybrid inheritance what we will do we will mix that for types of inheritance

10
00:00:24,970 --> 00:00:26,080
that we want to distribute.

11
00:00:26,080 --> 00:00:27,280
Let us take an example.

12
00:00:28,060 --> 00:00:34,720
So in we are Duplessis let's say see that it would even be now at this time I am using multiple in that

13
00:00:34,720 --> 00:00:37,660
it is now be inherited classy.

14
00:00:37,870 --> 00:00:45,060
So I am using my beloved inheritance here and now I am using hierarchal inheritance.

15
00:00:45,100 --> 00:00:45,620
OK.

16
00:00:45,670 --> 00:00:47,280
Let's take one more example.

17
00:00:47,320 --> 00:00:54,540
So suppose I have a class A now B and C both class in that it's from Class A.

18
00:00:55,100 --> 00:00:55,690
Okay.

19
00:00:55,750 --> 00:01:01,670
And now we have a class B which inherits from both Class B and Class C.

20
00:01:02,220 --> 00:01:04,470
OK so what will happen here is simple.

21
00:01:04,470 --> 00:01:10,420
So what over the structure of the guess over the list trophy the structural failure will be very simple.

22
00:01:10,480 --> 00:01:18,830
It will have only a specific properties then since being named from classy it will have a some B specific

23
00:01:18,830 --> 00:01:20,030
properties.

24
00:01:20,030 --> 00:01:21,420
So this is B.

25
00:01:21,710 --> 00:01:31,130
And the structure of C will be some C specific properties and a so where the structure of the the structure

26
00:01:31,130 --> 00:01:33,050
of the will be very simple.

27
00:01:33,050 --> 00:01:38,520
So this is D day inherits from Class B and C.

28
00:01:38,840 --> 00:01:46,420
So this is B B inherits from Class A and B specific properties.

29
00:01:46,510 --> 00:01:58,020
Similarly c c inherits from Class A C specific properties and then we will have some D specific properties.

30
00:01:58,020 --> 00:02:04,690
Okay now what will happen since Class D has two copies of glass.

31
00:02:05,310 --> 00:02:05,630
Okay.

32
00:02:05,650 --> 00:02:07,810
Glasby has two copies of glossy.

33
00:02:07,880 --> 00:02:10,760
So what it will do in future it will create ambiguity.

34
00:02:10,760 --> 00:02:12,370
How do we create ambiguity.

35
00:02:12,380 --> 00:02:18,580
Suppose this class he has a brain function inside public section.

36
00:02:18,630 --> 00:02:23,540
Okay so what will happen here we have a brain function.

37
00:02:23,750 --> 00:02:26,870
And similarly this is also a spring function.

38
00:02:26,870 --> 00:02:32,500
Now if we want to call print function that compiler will get confused which print function to call okay.

39
00:02:32,720 --> 00:02:35,170
So it will create ambiguity.

40
00:02:35,180 --> 00:02:37,640
Now let us take an example.

41
00:02:37,640 --> 00:02:45,260
So suppose we have a weekly class now both the classes God and truck they inherited from this working

42
00:02:45,260 --> 00:02:45,660
class.

43
00:02:45,680 --> 00:02:52,860
Okay so this is truck class and now bus class inherits from both car and truck.

44
00:02:53,390 --> 00:02:53,800
Okay.

45
00:02:53,900 --> 00:03:01,120
So this type of structure this is called a diamond problem and regret and be used in future.

46
00:03:01,130 --> 00:03:04,640
So this diamond problem it is a very well known problem.

47
00:03:04,640 --> 00:03:06,490
Okay so what will happen.

48
00:03:06,530 --> 00:03:07,760
So as we can see above.

49
00:03:08,330 --> 00:03:11,030
So this is also a diamond problem.

50
00:03:11,480 --> 00:03:15,260
So in Diamond problem we have ambiguity also.

51
00:03:15,470 --> 00:03:21,130
We have multiple copies Okay so due to multiple copies we will have ambiguity.

52
00:03:21,370 --> 00:03:26,760
Okay now our aim is to avoid multiple copy our aim is to avoid ambiguity.

53
00:03:26,760 --> 00:03:32,040
Okay now let's see in code how we can achieve the diamond problem and how we can resolve the diamond

54
00:03:32,040 --> 00:03:32,810
problem.

55
00:03:32,880 --> 00:03:41,800
Okay so let's say in called So this is our code we have of the class and inside the working class we

56
00:03:41,800 --> 00:03:50,290
have a default constructor a paramedic's constructor print function and a destructor Okay so we have

57
00:03:50,290 --> 00:03:53,950
a class card which inherits from the vehicle class.

58
00:03:53,950 --> 00:03:57,450
So we have a default constructor and a destructor.

59
00:03:57,680 --> 00:03:57,990
Okay.

60
00:03:58,450 --> 00:04:04,450
Similarly we have a class truck this also inherits from the working class and we have a constructor.

61
00:04:04,450 --> 00:04:12,760
Now here comes class bus it generates from class truck and also it generates from class got and it also

62
00:04:12,760 --> 00:04:14,370
inherits from class truck.

63
00:04:14,500 --> 00:04:18,110
And this is simple a constructor okay.

64
00:04:18,320 --> 00:04:20,790
So now our domain column is ready.

65
00:04:20,930 --> 00:04:28,230
And now let us first create the object of bus class okay so must be.

66
00:04:28,400 --> 00:04:30,180
Now what will happen if I add on this file.

67
00:04:30,200 --> 00:04:33,530
What would be the order of the constructor call let us try to understand

68
00:04:37,960 --> 00:04:50,370
so we have the class both the God and the truck class they inherited from the class and similarly class

69
00:04:50,370 --> 00:04:52,230
was inherited from God and truck.

70
00:04:52,500 --> 00:04:55,330
Okay so I am creating an object Busby.

71
00:04:55,410 --> 00:04:58,950
So what will happen first of all what was the order of the constructor call.

72
00:04:59,250 --> 00:05:01,970
So here we will write our order.

73
00:05:02,820 --> 00:05:04,100
So what will happen before.

74
00:05:04,380 --> 00:05:12,030
As soon as we create an object of must be we will go to God class to call it to call its constructor

75
00:05:12,030 --> 00:05:16,590
first by car class first because I have written car first and then truck.

76
00:05:16,590 --> 00:05:23,310
Okay so if we all know that before the bus class construct every bit called its parent class constructor

77
00:05:23,310 --> 00:05:25,830
will be called since there are two buildings car and truck.

78
00:05:25,920 --> 00:05:30,810
So first car class constructively record by car class because I have written God first.

79
00:05:31,110 --> 00:05:36,170
So God bless constructively required we will reach the car class and the parent of quiet classes vehicle.

80
00:05:36,360 --> 00:05:40,980
So we will go head and then the vehicle left constructor will call it first.

81
00:05:40,980 --> 00:05:47,250
So first of all we could constructively be called then we will reach to God again.

82
00:05:47,250 --> 00:05:54,110
Now the car at last constructed will be called then we will reach the bus and then we will each truck.

83
00:05:54,390 --> 00:05:59,940
So before calling their top class our class constructor truck will call its parent class constructor

84
00:05:59,970 --> 00:06:00,900
which is we call.

85
00:06:01,230 --> 00:06:05,720
So now that we like construct it will be called then we will come back to Truck.

86
00:06:05,730 --> 00:06:08,090
So now the top class constructor will be called.

87
00:06:08,160 --> 00:06:12,480
And now finally the best class constructor will be called okay.

88
00:06:12,480 --> 00:06:14,850
So this will be the order of the cost of protocol.

89
00:06:14,850 --> 00:06:15,260
Okay.

90
00:06:15,390 --> 00:06:20,520
So we can see here the working class constructor will be called twice.

91
00:06:21,300 --> 00:06:25,480
Okay so let us try to verify our output.

92
00:06:25,850 --> 00:06:26,960
So let's send this file

93
00:06:31,640 --> 00:06:32,780
so this is the order.

94
00:06:34,970 --> 00:06:37,700
So this is the order the first vehicle then God.

95
00:06:37,700 --> 00:06:39,870
Then again vehicle then truck and then bus.

96
00:06:39,910 --> 00:06:40,150
OK.

97
00:06:40,160 --> 00:06:42,470
So do not look like the order of the destructor.

98
00:06:42,470 --> 00:06:42,770
Why.

99
00:06:42,770 --> 00:06:45,530
Because we have not created district for every class.

100
00:06:45,530 --> 00:06:45,970
Okay.

101
00:06:46,100 --> 00:06:50,180
But we know the order of district will be just the opposite of the Order of the inheritance.

102
00:06:50,210 --> 00:06:54,150
Okay so the order of destructor will be the opposite of this.

103
00:06:54,180 --> 00:06:59,040
Okay.

104
00:06:59,280 --> 00:07:00,890
Now let's do one more thing.

105
00:07:00,900 --> 00:07:03,420
Let us try to call brain function.

106
00:07:03,420 --> 00:07:03,680
Okay.

107
00:07:03,690 --> 00:07:04,770
So be dot

108
00:07:07,930 --> 00:07:14,130
surveys the brain function so bus Gus doesn't have any print function proc doesn't have brain function.

109
00:07:14,160 --> 00:07:15,990
Similarly car doesn't have brain function.

110
00:07:15,990 --> 00:07:21,630
Actually it has print function but we have commanded it out so we could gloss has the print function

111
00:07:21,960 --> 00:07:26,620
since the print function is public it is accessible to every derived class.

112
00:07:26,670 --> 00:07:26,970
Okay.

113
00:07:27,000 --> 00:07:29,670
So be has access to the print function.

114
00:07:29,700 --> 00:07:32,540
So that means we will not get an error due to accessibility.

115
00:07:32,630 --> 00:07:35,460
Let's see whether we will get in that error or not.

116
00:07:35,460 --> 00:07:40,090
So we will get we will definitely get an error and that it will be due to ambiguity.

117
00:07:40,110 --> 00:07:43,400
So what is happening what is the structure of bus class.

118
00:07:43,560 --> 00:07:45,600
So the structure of bus class is quite simple

119
00:07:48,450 --> 00:07:50,280
so this is our bus class.

120
00:07:50,280 --> 00:07:53,350
So bus class inherits from car and truck.

121
00:07:53,580 --> 00:08:03,670
So this is car and this is truck so inside the car plus I have the class we can.

122
00:08:03,700 --> 00:08:07,690
And similarly to class inherits from the class.

123
00:08:07,750 --> 00:08:14,740
So this vehicle class has brain function and this working class is also high Sprint function.

124
00:08:14,740 --> 00:08:17,410
Basically both the print function are exactly the same.

125
00:08:17,410 --> 00:08:18,000
Okay.

126
00:08:18,010 --> 00:08:20,290
So when will run the file.

127
00:08:20,290 --> 00:08:26,650
We will get in the red line number 17 that print function is present in multiple base classes.

128
00:08:26,710 --> 00:08:27,100
Okay.

129
00:08:27,100 --> 00:08:28,640
There will be ambiguity problem.

130
00:08:28,660 --> 00:08:30,580
I'll get compiler will get confused.

131
00:08:30,580 --> 00:08:32,020
Which print function to call.

132
00:08:32,040 --> 00:08:34,600
Although both the print function are exactly the same.

133
00:08:34,600 --> 00:08:36,900
But compiler will get confused.

134
00:08:36,970 --> 00:08:45,420
Okay so now let's send this file to see so we are getting an error and that is due to ambiguity.

135
00:08:45,420 --> 00:08:48,720
You can see that and also so print is ambiguous.

136
00:08:48,750 --> 00:08:49,670
Okay.

137
00:08:50,130 --> 00:08:52,030
Now how can we resolve this header.

138
00:08:52,140 --> 00:08:54,660
So there are two ways to resolve this error.

139
00:08:54,690 --> 00:08:59,150
First way is to add a print function inside the bus glass.

140
00:08:59,190 --> 00:08:59,660
Okay.

141
00:08:59,760 --> 00:09:07,350
So as soon as we will as soon as we write a print function inside the bus glass and beauty problem will

142
00:09:07,350 --> 00:09:15,660
be resolved widely as all because in the last session because in the last radio we have seen that whenever

143
00:09:15,740 --> 00:09:23,520
a whenever a class so in the last few days we have seen that whenever a class as a function of its own

144
00:09:23,550 --> 00:09:28,460
then first of all we will check the bus class only since the bus class has the print function.

145
00:09:28,470 --> 00:09:30,450
We will not go to its parent class.

146
00:09:30,580 --> 00:09:30,860
OK.

147
00:09:30,870 --> 00:09:32,930
So there will be no ambiguity.

148
00:09:32,970 --> 00:09:36,660
So when I call this function without print this brain function will be called.

149
00:09:36,860 --> 00:09:37,430
Okay.

150
00:09:37,470 --> 00:09:38,700
And our output will be buzz.

151
00:09:39,780 --> 00:09:41,070
Okay so let's send this file

152
00:09:44,580 --> 00:09:46,880
so I would output this bus.

153
00:09:46,890 --> 00:09:48,180
Okay.

154
00:09:48,180 --> 00:09:51,690
Now that and other way to solve this problem is to specify the class.

155
00:09:51,690 --> 00:09:52,310
Okay.

156
00:09:52,440 --> 00:09:55,020
We will specify the class since both.

157
00:09:55,030 --> 00:09:56,450
So what is the structure.

158
00:09:56,640 --> 00:09:59,340
So let us write the structure here.

159
00:09:59,340 --> 00:10:00,990
Okay so let's write the structure.

160
00:10:00,990 --> 00:10:02,440
So we have.

161
00:10:03,360 --> 00:10:18,800
So we have this class bus this bus glass inherits from God and from truck and this is the class.

162
00:10:18,880 --> 00:10:20,920
So this is also a vehicle.

163
00:10:21,430 --> 00:10:25,090
This will go class has a print function.

164
00:10:25,090 --> 00:10:27,740
This will allow us all to this brain function.

165
00:10:27,790 --> 00:10:31,890
And now let us comment out the brain function of the bus class.

166
00:10:31,900 --> 00:10:36,310
Okay now bus class doesn't have in the print function.

167
00:10:36,340 --> 00:10:39,020
So when I write B dot print what will happen.

168
00:10:39,220 --> 00:10:44,100
Obviously we will get an error because two print functions are already there.

169
00:10:44,140 --> 00:10:44,430
Okay.

170
00:10:44,440 --> 00:10:48,380
So to resolve this error the second way was to specify the class name.

171
00:10:48,640 --> 00:10:52,350
So either we have to specify the car or we have to specify the truck.

172
00:10:52,360 --> 00:10:57,160
We cannot specify the vehicle because both car and truck as we call it will not so on what ambiguity

173
00:10:57,160 --> 00:10:58,000
problem.

174
00:10:58,000 --> 00:11:01,390
So we have to specify our data card or either truck.

175
00:11:01,480 --> 00:11:01,890
Okay.

176
00:11:02,020 --> 00:11:03,920
So let us specify the car.

177
00:11:04,240 --> 00:11:09,570
So we will write we dart card and then scope resolution operator okay.

178
00:11:09,880 --> 00:11:16,040
So let's send this file so now I would put this vehicle.

179
00:11:16,060 --> 00:11:19,280
Okay so our problem is resolved.

180
00:11:19,280 --> 00:11:20,090
Now what if

181
00:11:22,870 --> 00:11:27,830
notify and comment the print function of the car plus.

182
00:11:27,870 --> 00:11:29,480
So what will happen now.

183
00:11:29,490 --> 00:11:30,010
Okay.

184
00:11:30,120 --> 00:11:37,400
So what happened is we have this glass cut this glass also has a brain function of its own.

185
00:11:37,410 --> 00:11:40,660
Now what will happen if I write.

186
00:11:40,930 --> 00:11:45,410
So if I write B dot God it's called resolution or greater print.

187
00:11:45,480 --> 00:11:46,650
What will happen.

188
00:11:46,650 --> 00:11:58,230
So when I write B dot God scope resolution operator and then the print function and if I had eight B

189
00:11:58,230 --> 00:12:07,150
dart print and if I had eight B dart school resolution operator and print.

190
00:12:07,840 --> 00:12:11,380
So what will the output of all these three lines.

191
00:12:11,380 --> 00:12:15,120
Okay so first of all world output of this line.

192
00:12:15,120 --> 00:12:21,030
So first of all this line will throw us at it via debt because inside the bus function we do not have

193
00:12:21,030 --> 00:12:23,910
any print function since we do not have brain function.

194
00:12:23,910 --> 00:12:30,060
We will go to its parent class which is God in print and now there will be ambiguity why ambiguity because

195
00:12:30,150 --> 00:12:33,670
there are now three print functions okay.

196
00:12:33,770 --> 00:12:35,240
That t print functions now.

197
00:12:35,240 --> 00:12:37,240
So there will be ambiguity.

198
00:12:37,340 --> 00:12:38,920
So obviously this will throw us at it.

199
00:12:39,890 --> 00:12:40,520
Okay.

200
00:12:40,520 --> 00:12:45,490
Now let's see this beat out God school resolution operator and print.

201
00:12:45,560 --> 00:12:49,260
Now what do we do it very clearly specifies go to go of class.

202
00:12:49,310 --> 00:12:51,900
And since the kind class has print function of its own.

203
00:12:52,200 --> 00:12:54,700
So this print function will be called.

204
00:12:54,940 --> 00:12:55,600
Okay.

205
00:12:55,640 --> 00:12:59,050
And B Da plUG Scott resolution operator print will happen.

206
00:12:59,120 --> 00:13:00,660
We will go to class.

207
00:13:00,680 --> 00:13:02,690
Class do not have print function of its own.

208
00:13:02,690 --> 00:13:06,430
So it will go to its parent class parent class s print function.

209
00:13:06,590 --> 00:13:09,310
So print this time this print function will be called.

210
00:13:09,320 --> 00:13:09,980
Okay.

211
00:13:09,980 --> 00:13:16,170
So it will call this one and it will call this one.

212
00:13:16,420 --> 00:13:25,600
Okay let's send this file so what we are output now this brain function will be called Card print function.

213
00:13:25,600 --> 00:13:33,990
Okay let's send this file so we can see here num dials num gives.

214
00:13:34,000 --> 00:13:34,300
Okay.

215
00:13:34,330 --> 00:13:36,290
So now I'm biased num gives and colors.

216
00:13:36,310 --> 00:13:42,580
So God brain function is being getting call okay.

217
00:13:42,750 --> 00:13:47,380
Now we have cleared them beauty but still there is one big problem.

218
00:13:47,460 --> 00:13:47,720
Okay.

219
00:13:47,730 --> 00:13:48,990
So what is the big problem.

220
00:13:49,920 --> 00:13:51,310
So ambiguities is old.

221
00:13:51,390 --> 00:13:55,740
Now we all know ambiguities is all but there is still one very big problem that we need to handle.

222
00:13:56,220 --> 00:14:03,660
And the very big problem is that there are two copies clause D will have two copies of glass.

223
00:14:04,170 --> 00:14:16,630
Okay so this is glass D and inside the glass V I have glass B glass B has a and similarly class C has

224
00:14:16,690 --> 00:14:16,910
a.

225
00:14:17,710 --> 00:14:22,230
Okay so here we have two copies of glass a.

226
00:14:22,340 --> 00:14:24,100
Now we have to solve this problem.

227
00:14:24,170 --> 00:14:24,870
Okay.

228
00:14:25,010 --> 00:14:27,110
I definitely we want only one copy.

229
00:14:27,110 --> 00:14:29,260
We need only one copy of glass a.

230
00:14:29,320 --> 00:14:29,590
Okay.

231
00:14:29,600 --> 00:14:32,620
So we have to avoid this copying how can we avoid this copying.

232
00:14:32,630 --> 00:14:35,240
We can use the keyboard what tool.

233
00:14:35,240 --> 00:14:35,720
Okay.

234
00:14:35,840 --> 00:14:37,330
So there is a keyword.

235
00:14:37,420 --> 00:14:39,030
What tool.

236
00:14:39,360 --> 00:14:40,350
Now let's see.

237
00:14:40,350 --> 00:14:48,600
Well we have to write a tool to solve this copy problem so glass card before writing the public.

238
00:14:48,600 --> 00:14:55,790
We will write virtual and similarly for track class we have to write what tool

239
00:14:58,820 --> 00:14:59,360
okay.

240
00:14:59,400 --> 00:15:00,930
Now what this virtual will do.

241
00:15:01,020 --> 00:15:07,050
So this virtual will ensure that class D will now have only one copy of class A.

242
00:15:07,200 --> 00:15:09,960
Okay so let's come in this out.

243
00:15:11,070 --> 00:15:13,950
So now we are creating an object of bus B.

244
00:15:14,130 --> 00:15:18,780
So if I will run this file what with the order of the constructor call let us try to understand

245
00:15:22,940 --> 00:15:34,320
so I have this working class then car and truck so guide classes in editing class classical but we have

246
00:15:34,320 --> 00:15:36,120
a keyboard virtual okay.

247
00:15:36,240 --> 00:15:39,180
We are in editing the class but we have a keyword virtual.

248
00:15:39,180 --> 00:15:41,310
So what what should we do.

249
00:15:41,310 --> 00:15:45,180
Let's try to understand and we have bus here.

250
00:15:45,180 --> 00:15:45,900
Okay.

251
00:15:45,960 --> 00:15:48,090
So C must be.

252
00:15:48,210 --> 00:15:55,220
So what will happen so first of all where the best class will do it will go to its parent class to call

253
00:15:55,220 --> 00:16:01,880
its default constructor so will reach GA class since the Cairo class is virtually inheriting from the

254
00:16:01,940 --> 00:16:02,720
working class.

255
00:16:03,140 --> 00:16:04,240
So what will happen.

256
00:16:04,340 --> 00:16:11,330
Bus class will call the vehicle class bus class will call the constructor their default constructor

257
00:16:11,330 --> 00:16:18,290
of the vehicle class so the order of the the order of the constructor call will be first this vehicle

258
00:16:18,290 --> 00:16:22,580
glass constructor will be called and who will call boss class constructor will be called.

259
00:16:22,670 --> 00:16:28,800
This cannot call that God cannot call because they are inheriting the vehicle glass of water surely

260
00:16:28,820 --> 00:16:30,820
so they cannot call the constructor.

261
00:16:30,860 --> 00:16:37,670
Okay so first it will be called victory in this construct and will be called then God class and then

262
00:16:37,670 --> 00:16:41,030
track class and then finally the best class constructor will be called.

263
00:16:41,210 --> 00:16:49,580
So as we can see here the class construct will be called only once okay and who will call but will call

264
00:16:49,970 --> 00:16:53,670
neither God nor truck.

265
00:16:53,750 --> 00:16:56,530
Okay so let's let's see the.

266
00:16:56,630 --> 00:17:04,920
Now let's run this file so as you can see first recalled car truck and then bus.

267
00:17:05,010 --> 00:17:10,730
OK so because construct based call only once not twice alert was called place.

268
00:17:10,850 --> 00:17:11,130
OK.

269
00:17:11,180 --> 00:17:12,990
But here it will recall only once.

270
00:17:13,010 --> 00:17:15,780
And who will call boss class will call.

271
00:17:15,810 --> 00:17:19,610
OK so what is the concept of a virtual based class.

272
00:17:19,610 --> 00:17:19,840
OK.

273
00:17:19,850 --> 00:17:21,590
So how we're actually helping here.

274
00:17:23,160 --> 00:17:27,780
What is the purpose of like what is the meaning of this virtual based class.

275
00:17:27,780 --> 00:17:28,270
Okay.

276
00:17:28,380 --> 00:17:32,650
So earlier what was happening this car plus

277
00:17:35,530 --> 00:17:38,170
has object as object of virtual class.

278
00:17:38,170 --> 00:17:41,980
So this was really a situation before using the virtual keyboard.

279
00:17:41,980 --> 00:17:48,060
Now we are using what tool show vehicle glasses now a virtual based class.

280
00:17:48,070 --> 00:17:49,080
So what will happen now.

281
00:17:50,910 --> 00:17:57,710
So this is got a glass This is glass.

282
00:17:57,960 --> 00:18:05,200
So earlier the gardener truck glass they have the actual vehicle object but now they will have a pointer.

283
00:18:05,520 --> 00:18:14,360
Similarly truck will have a pointer to the vehicle object they now have a pointer to difficult object

284
00:18:14,630 --> 00:18:22,550
earlier they have the vehicle object but now they have a pointer to the vehicle object.

285
00:18:22,550 --> 00:18:22,900
Okay.

286
00:18:22,910 --> 00:18:35,060
And really the structure of the bus so Elliot bus only has got an object but no bus will have vehicle

287
00:18:35,060 --> 00:18:38,690
object it will have cart object and it will have object.

288
00:18:38,960 --> 00:18:45,170
So that's why a bus will call the vehicle's last constructor no ID card neither car neither truck.

289
00:18:45,320 --> 00:18:53,330
OK so bus will be able to call the world class constructor working class constructor and God and I cannot

290
00:18:53,330 --> 00:18:59,670
call the vehicle class constructor because they only have pointer and not the actual object.

291
00:18:59,930 --> 00:19:02,510
Okay so now we are avoiding the copy.

292
00:19:02,570 --> 00:19:02,970
Okay.

293
00:19:02,990 --> 00:19:06,290
So now we had a wedding copy we only have one copy.

294
00:19:06,290 --> 00:19:09,810
There are not multiple copies.

295
00:19:10,000 --> 00:19:10,690
Okay.

296
00:19:10,930 --> 00:19:12,920
Now let's see one more thing.

297
00:19:12,930 --> 00:19:13,200
Okay

298
00:19:17,420 --> 00:19:17,730
okay.

299
00:19:17,740 --> 00:19:23,420
So now let's come in out the cost of the default construct of the class.

300
00:19:23,450 --> 00:19:25,000
Now what will happen.

301
00:19:25,010 --> 00:19:25,530
Okay.

302
00:19:25,610 --> 00:19:30,890
So since we have better merge based constructor so the default construct better if we could class is

303
00:19:30,890 --> 00:19:33,970
not visible to us okay.

304
00:19:34,030 --> 00:19:37,510
So what will happen.

305
00:19:37,570 --> 00:19:40,020
So now we have to call the Better based constructor.

306
00:19:40,030 --> 00:19:44,230
OK so since the default constructor weaker class is not visible.

307
00:19:44,230 --> 00:19:50,590
So now we have to call this better my place to construct explicitly because implicitly a child class

308
00:19:50,590 --> 00:19:54,450
can only call the default constructor of its parent class.

309
00:19:54,630 --> 00:19:54,870
Okay.

310
00:19:54,880 --> 00:20:01,190
So if you will run this file must be let us on this file so we are getting an error and let's see that.

311
00:20:01,190 --> 00:20:12,110
What is that it so the error is so bad it is Truck Bus and God so we are getting an error in all the

312
00:20:12,110 --> 00:20:16,990
three classes got bus and wave struck.

313
00:20:17,090 --> 00:20:18,190
So this is truck.

314
00:20:18,610 --> 00:20:22,550
Okay so we are getting an error in all the three classes.

315
00:20:22,550 --> 00:20:28,070
So what is happening here is so in the last three videos I told you that a class can only call the constructor

316
00:20:28,070 --> 00:20:29,950
of its immediate parent.

317
00:20:30,230 --> 00:20:35,810
But here the bus class is calling construct of its grandparent.

318
00:20:35,840 --> 00:20:37,930
Okay so this is a special case.

319
00:20:37,970 --> 00:20:38,270
Okay.

320
00:20:38,270 --> 00:20:43,460
I'm repeating myself in their libidos I told you that a class can only call the concept of profits immediate

321
00:20:43,460 --> 00:20:44,040
parent.

322
00:20:44,140 --> 00:20:48,460
But here the bus glass is quoting the construct proffered grandparent.

323
00:20:48,590 --> 00:20:52,820
Okay but only in this case because we are using the virtual keyword.

324
00:20:52,820 --> 00:20:53,300
Okay.

325
00:20:53,420 --> 00:20:56,710
We are making the weekend class as virtual base class.

326
00:20:56,750 --> 00:21:01,790
Okay so only in this case class can call the constructor of its grandparent.

327
00:21:01,790 --> 00:21:06,580
Okay so this type of inheritance is also known as what actually inheritance.

328
00:21:06,590 --> 00:21:06,850
Okay.

329
00:21:06,890 --> 00:21:10,040
So this type of an identity also known as virtual inheritance.

330
00:21:10,040 --> 00:21:12,020
Now let's solve this problem.

331
00:21:12,020 --> 00:21:15,790
So how can we solve this problem since we do not have any default constructor.

332
00:21:15,800 --> 00:21:23,190
We have to call it bottom at best constructor explicitly so class got so with the help of initialization

333
00:21:23,190 --> 00:21:28,890
list we can let's say three okay.

334
00:21:28,900 --> 00:21:32,530
So let's spend the value of Z here

335
00:21:37,480 --> 00:21:39,230
so I am bringing the value of Z also.

336
00:21:39,320 --> 00:21:39,790
Okay.

337
00:21:40,860 --> 00:21:42,320
Now I am bringing the value of Z.

338
00:21:42,330 --> 00:21:44,950
You will understand in some time so.

339
00:21:44,990 --> 00:21:45,420
Truck

340
00:21:48,620 --> 00:21:54,210
the call and let's say the value is for we are calling the paramedics construct.

341
00:21:54,260 --> 00:21:54,880
Okay.

342
00:21:54,920 --> 00:22:01,630
And similarly we have to do for bus also because bus also has the object of because class.

343
00:22:01,650 --> 00:22:02,400
Okay.

344
00:22:02,700 --> 00:22:09,710
This is a special case we had a we had a class can call the concept of its grandparent Okay and let's

345
00:22:09,720 --> 00:22:10,710
say the value is

346
00:22:13,630 --> 00:22:15,090
and let's say the value is five.

347
00:22:15,240 --> 00:22:16,470
Okay.

348
00:22:17,100 --> 00:22:19,650
So value 3.

349
00:22:19,650 --> 00:22:23,270
Value for value 4 and value 5.

350
00:22:23,690 --> 00:22:23,960
Okay.

351
00:22:23,960 --> 00:22:29,830
And I am bringing the value of Z here Okay let's send this file

352
00:22:33,970 --> 00:22:37,870
so you can see what is the value getting printed 5.

353
00:22:38,140 --> 00:22:40,140
This is the proof variable used 5.

354
00:22:40,150 --> 00:22:42,050
Here okay.

355
00:22:42,160 --> 00:22:44,020
So here we are using 5.

356
00:22:44,020 --> 00:22:45,430
So this is the proof.

357
00:22:45,670 --> 00:22:46,020
Okay.

358
00:22:46,060 --> 00:22:53,070
So we have proved that bus glasses is calling the victim class constructor and not the car in the truck.

359
00:22:53,330 --> 00:22:59,840
Okay so I hope now you understand where this diamond problem and how we can use virtual keyword and

360
00:23:00,290 --> 00:23:03,070
how to resolve ambiguity and how to avoid copy.

361
00:23:03,080 --> 00:23:03,530
Okay.

362
00:23:03,590 --> 00:23:03,980
Thank you.
