1 00:00:00,210 --> 00:00:07,250 So our next up against polymorphism will chat functions and abstract classes, so this is most like 2 00:00:07,590 --> 00:00:10,800 kind of a special topic we are covering today. 3 00:00:11,010 --> 00:00:14,260 So let us deep dive into polymorphism answer. 4 00:00:14,910 --> 00:00:23,610 So among one polymorphism concept you have already discussed in our previous section, which was basically 5 00:00:23,610 --> 00:00:27,030 on all our learning, like we had different operators, right? 6 00:00:27,360 --> 00:00:31,500 And we now are using these operators for a different purpose. 7 00:00:31,830 --> 00:00:33,900 So like we had, let's celebrate that. 8 00:00:34,050 --> 00:00:38,370 But we changed the meaning of the plus operator in our previous classes. 9 00:00:38,370 --> 00:00:42,870 So that's an example of what a polymorphism which means polymorphism means. 10 00:00:42,870 --> 00:00:47,880 Multiple forms like the same thing is achieved differently. 11 00:00:48,090 --> 00:00:56,940 So we had a list operator and we were using that cluster operator for both adding numbers and also concatenating 12 00:00:56,940 --> 00:00:57,750 some strings. 13 00:00:58,020 --> 00:01:03,990 So that's an example for that polymorphism, which means like the same operator was used in different 14 00:01:03,990 --> 00:01:04,470 forms. 15 00:01:04,680 --> 00:01:11,370 Similarly, we do have one more concept in C++, which is called runtime polymorphism. 16 00:01:11,910 --> 00:01:20,550 So for achieving runtime polymorphism, we usually use our feature in C++ GUI virtual function. 17 00:01:20,790 --> 00:01:24,600 So let's discuss what is meant by individual function. 18 00:01:24,600 --> 00:01:30,830 First ever virtual function, a simple function we just declared within a base class and redefined by 19 00:01:30,830 --> 00:01:31,650 a class. 20 00:01:31,950 --> 00:01:43,800 Suppose we have two classes Class A and Class B, so Class A is the bad and class, and Class B is actually 21 00:01:43,800 --> 00:01:50,670 that derived class or inheriting the properties of that class and supports classes having a property 22 00:01:50,670 --> 00:01:51,750 on a function card. 23 00:01:52,210 --> 00:01:53,910 So that's a function. 24 00:01:54,390 --> 00:02:02,160 And in class AA, it's having a meaning like we want to change the meaning while we are impacting the 25 00:02:02,670 --> 00:02:04,230 same function to Class B. 26 00:02:04,680 --> 00:02:05,100 OK. 27 00:02:05,340 --> 00:02:09,750 So for that purpose, we use a concept like virtual function. 28 00:02:09,990 --> 00:02:16,380 What we will do is like we will actually define our show function as it will actually function inside 29 00:02:16,380 --> 00:02:17,640 the bat and class. 30 00:02:17,650 --> 00:02:20,370 It will be like virtual show. 31 00:02:20,520 --> 00:02:28,320 And this will gosse that we can change the definition of this show function being headed that same show 32 00:02:28,320 --> 00:02:30,220 of function in under Class B. 33 00:02:30,240 --> 00:02:33,270 So that's that symbol for it with a gel function. 34 00:02:33,570 --> 00:02:37,640 And in order to make a function virtual, we use a key word like what? 35 00:02:38,130 --> 00:02:38,520 OK? 36 00:02:38,820 --> 00:02:44,820 And when actually the function definition is taken into consideration. 37 00:02:45,030 --> 00:02:49,320 It's only during the runtime, usually in C++. 38 00:02:49,560 --> 00:02:56,940 Most of the things most of the meanings of the function, most of that are like definitions, resolution 39 00:02:56,940 --> 00:02:57,660 of variables. 40 00:02:57,840 --> 00:03:01,340 Everything will take place at compile time. 41 00:03:01,620 --> 00:03:07,650 But if we are using a virtual function, the meaning of that virtual function is derived or let that 42 00:03:07,950 --> 00:03:08,550 runtime. 43 00:03:08,580 --> 00:03:13,200 So that's the difference between a normal function and it will actually function. 44 00:03:13,590 --> 00:03:20,580 So I have already discussed this topic, so we have polymorphism, which means processing the same thing 45 00:03:20,580 --> 00:03:21,660 in different ways. 46 00:03:21,960 --> 00:03:22,370 OK. 47 00:03:22,470 --> 00:03:25,320 And the polymorphism can be divided into two. 48 00:03:25,530 --> 00:03:32,550 One is compile time polymorphism, and it's having two separate divisions, as I discussed already function, 49 00:03:32,580 --> 00:03:37,530 overloading and operating our learning, which we have already covered in our previous section. 50 00:03:37,830 --> 00:03:44,250 Now we have one more type of polymorphism, which is called runtime polymorphism, which will actually 51 00:03:44,250 --> 00:03:47,160 depend on the work functions concept. 52 00:03:47,340 --> 00:03:55,170 So let's dive into the demo right now so that you will be able to understand how the gel functions work. 53 00:03:55,500 --> 00:03:57,390 So I will explain this program to you. 54 00:03:57,690 --> 00:04:04,590 So it's having two classes one classes, card bays, glass and another classes derived class, and you 55 00:04:04,590 --> 00:04:12,540 can see a single inheritance happening out here like glass derived is actually inheriting the properties 56 00:04:12,540 --> 00:04:13,500 of base class. 57 00:04:13,770 --> 00:04:21,000 And we do have dual functions inside our base class one, this virtual white brain function and virtual 58 00:04:21,000 --> 00:04:21,480 function. 59 00:04:21,840 --> 00:04:27,150 And what happens when you execute brain function in base class? 60 00:04:27,150 --> 00:04:30,870 It will print brain based class that will be the output. 61 00:04:31,140 --> 00:04:36,420 And what happens when you bring the show function from the base class? 62 00:04:36,630 --> 00:04:39,690 It will just print show based class. 63 00:04:39,960 --> 00:04:40,350 OK. 64 00:04:40,590 --> 00:04:44,430 And now we are deriving that and we are redefining that. 65 00:04:44,730 --> 00:04:53,280 But if you look at here this white print, it's actually printing this derived class and show is also 66 00:04:53,280 --> 00:04:57,660 redefined out yet and it will be printing the entire class. 67 00:04:57,820 --> 00:04:58,200 OK. 68 00:04:58,500 --> 00:04:59,700 It will be showing that at. 69 00:05:00,100 --> 00:05:02,080 That will be the output of this function. 70 00:05:02,290 --> 00:05:08,880 What is happening is like we are actually creating a wind up for our very own glass. 71 00:05:09,020 --> 00:05:09,340 OK. 72 00:05:09,580 --> 00:05:16,660 We are creating our point effort for their glass out here and we are actually printing the function, 73 00:05:16,990 --> 00:05:20,140 OK, using the brain function of that child object. 74 00:05:20,260 --> 00:05:20,710 OK. 75 00:05:21,070 --> 00:05:28,030 So it will be like that object is what drives glass and it will be printing the value for the glass 76 00:05:28,570 --> 00:05:36,070 so that the rind glass object is D. So it's equal to the entire brain, and this is equal to the brain 77 00:05:36,070 --> 00:05:40,360 because this is a pointer of an object that we have already discussed. 78 00:05:40,600 --> 00:05:41,970 So you will be at mass any. 79 00:05:42,040 --> 00:05:49,300 You can access this drive glass and access that brain by using this index so it will be actually binding 80 00:05:49,300 --> 00:05:52,240 to this glass and it will be executing this print. 81 00:05:52,660 --> 00:06:02,500 And now we do have one more thing like show function, which is also like printing on that order here, 82 00:06:02,770 --> 00:06:03,070 right? 83 00:06:03,340 --> 00:06:09,070 It will be like printing show derived glass, but it's also inside the building of the glass. 84 00:06:09,250 --> 00:06:11,950 But what happens when you execute this function? 85 00:06:12,040 --> 00:06:13,690 So that's something we need to know, right? 86 00:06:13,870 --> 00:06:20,770 So let me switch to desktop now you have to compile this fire. 87 00:06:20,770 --> 00:06:27,390 So we have the syntax C++, the ritual FNC, dark CBB. 88 00:06:27,910 --> 00:06:28,890 Now it's come by. 89 00:06:29,110 --> 00:06:33,320 Now let's bring it by or out to get out of dodge. 90 00:06:33,330 --> 00:06:34,180 Slash it out. 91 00:06:34,750 --> 00:06:37,570 See if you know what is on here. 92 00:06:38,050 --> 00:06:45,970 The drive glass is actually printing that using the print function out here, but many also here. 93 00:06:46,480 --> 00:06:50,260 The show function is not showing that the right glass. 94 00:06:50,950 --> 00:06:56,680 This should be the output of the show function, but it's just printing that show based glass. 95 00:06:56,680 --> 00:07:00,310 That means it's actually printing the show function or here.