1 00:00:00,360 --> 00:00:04,620 Let's move on to the important topic of kind of tech doesn't distract us. 2 00:00:04,740 --> 00:00:12,420 So can you stick that in C++ is a special function that is automatically called when an object of glass 3 00:00:12,420 --> 00:00:13,040 is created. 4 00:00:13,050 --> 00:00:18,750 So each time when you create that object for a particular class, we will be having a constructor, 5 00:00:18,990 --> 00:00:22,050 which is a special function which is defined inside the class. 6 00:00:22,050 --> 00:00:27,490 That will be the first person to be knocked out of that with the first person which will be caught that, 7 00:00:28,380 --> 00:00:33,570 you know, automatically mean not to call it passively and construct those optional components of a 8 00:00:33,570 --> 00:00:33,990 glass. 9 00:00:34,170 --> 00:00:40,560 So you need to create a conflict that before it will be starting to work so that it would be an noted 10 00:00:40,560 --> 00:00:41,670 before constructor. 11 00:00:41,880 --> 00:00:43,920 But you need to create a sector. 12 00:00:44,310 --> 00:00:46,690 Creating a constructor is very easy. 13 00:00:46,710 --> 00:00:49,190 You need to use the name of that class. 14 00:00:49,200 --> 00:00:52,980 OK, and parentheses class names should be your same class name. 15 00:00:53,130 --> 00:00:54,720 Which class named are going to stick to. 16 00:00:54,960 --> 00:00:59,790 The name of that last name will be used and followed by a parentheses. 17 00:00:59,790 --> 00:01:05,700 You will understand this when you explore the syntax, and constructor will have exact same name of 18 00:01:05,700 --> 00:01:06,240 the class. 19 00:01:06,240 --> 00:01:11,970 When buying, you have to notice and each does not have to return any type at all. 20 00:01:12,000 --> 00:01:14,310 And sector will not be having any return date. 21 00:01:14,520 --> 00:01:18,570 So Constructor is all that function, but it does not have a return date. 22 00:01:18,720 --> 00:01:24,810 So you need not to specify the return date when you create that construct that not even moit return 23 00:01:24,810 --> 00:01:26,610 type is specified in this index. 24 00:01:26,610 --> 00:01:31,560 And constructors can be very useful for setting initial values for certain member variables. 25 00:01:31,560 --> 00:01:37,380 So if you want to set the values of a particular variable, you can use that constructor. 26 00:01:37,410 --> 00:01:40,290 Now, let's go to destructor so distracted. 27 00:01:40,290 --> 00:01:42,780 I'm going to check I'm covering it right away together. 28 00:01:42,870 --> 00:01:49,980 So there is a special member function whenever, like an object is deleted, every memory allocated 29 00:01:49,980 --> 00:01:53,350 for object is deleted when the program is completed. 30 00:01:53,370 --> 00:01:53,790 OK. 31 00:01:53,850 --> 00:01:57,990 So whenever the object is deleted, there will be a destructive. 32 00:01:58,030 --> 00:01:58,500 OK. 33 00:01:58,710 --> 00:02:02,100 Structure will be executed like District 10 will be doing. 34 00:02:02,460 --> 00:02:07,650 It will be just clearing out all the variables clearing the values of that memory. 35 00:02:07,680 --> 00:02:13,980 OK, why we should use destructor the cleanup will be automatically done by that computer when the program 36 00:02:13,980 --> 00:02:14,970 execution is complete. 37 00:02:15,090 --> 00:02:21,180 But if you want to mention something or if you want to do some activities while this cleanup is being 38 00:02:21,180 --> 00:02:23,580 carried out, then we will be using that district. 39 00:02:23,970 --> 00:02:25,740 And how will you get to create a district that? 40 00:02:25,740 --> 00:02:26,820 It's very simple. 41 00:02:26,970 --> 00:02:33,990 It's similar to that of a constructor, but you have to use a little saying this is that D.D.S. while 42 00:02:34,230 --> 00:02:39,850 you will be creating a district, so it will have the same name of the class followed by it. 43 00:02:40,230 --> 00:02:45,300 Before that, it was there will be a TV set, so it's better to see the demo for understanding this 44 00:02:45,300 --> 00:02:45,780 concept. 45 00:02:46,110 --> 00:02:49,510 You will be able to see this by sector and just like that right here. 46 00:02:49,530 --> 00:02:50,190 OK? 47 00:02:50,220 --> 00:02:56,430 We have a constructor program created here and we have class named guide and we have string brand and 48 00:02:56,430 --> 00:02:57,270 string model. 49 00:02:57,420 --> 00:03:00,850 Then we have a kind of set up later here. 50 00:03:00,870 --> 00:03:02,220 This is the constructor. 51 00:03:02,220 --> 00:03:06,860 OK, so constructor, what car constructor knows? 52 00:03:06,900 --> 00:03:12,570 You can see out of here that last name is Scott, and the constructor name is also car constructor is 53 00:03:12,570 --> 00:03:14,310 a function you can see it's having. 54 00:03:14,310 --> 00:03:19,350 It operates right and then it's having it go live in a shopping cart based car. 55 00:03:19,410 --> 00:03:23,760 So this is also a function, but there is no return date, no white noise. 56 00:03:23,760 --> 00:03:25,550 No, and nothing is mentioned out here. 57 00:03:25,710 --> 00:03:31,710 But this current structure and function can access or get three variables X right? 58 00:03:31,710 --> 00:03:32,220 And is it? 59 00:03:32,220 --> 00:03:37,150 And why does a use of the constructor is the variables inside that object? 60 00:03:37,170 --> 00:03:41,700 So we have three variables created inside the car class that is brand model. 61 00:03:41,720 --> 00:03:46,950 And yet and you can supply values that three variables during that creation of the object. 62 00:03:46,950 --> 00:03:48,870 That's why you use it, constructor. 63 00:03:49,050 --> 00:03:53,130 So branding callbacks and modelling all the way on D.N.A. is that x y? 64 00:03:53,130 --> 00:03:54,090 And is that OK? 65 00:03:54,210 --> 00:03:55,440 So what happens? 66 00:03:55,960 --> 00:03:58,050 I'm going to the main function. 67 00:03:58,050 --> 00:04:05,040 I'm creating an object called card object, and God object is passing three values BMW, X5 and one 68 00:04:05,040 --> 00:04:06,100 nine nine nine, right? 69 00:04:06,130 --> 00:04:10,260 How what will happen this when this car object is created? 70 00:04:10,260 --> 00:04:15,150 At first, this constructor will be card and what will happen when this sector will be caught. 71 00:04:15,150 --> 00:04:19,780 It will supply three values already at BMW, X5 and one 1999. 72 00:04:19,920 --> 00:04:20,370 OK. 73 00:04:20,850 --> 00:04:22,740 So it will be coming like this. 74 00:04:22,740 --> 00:04:25,320 X will be equal to BMW X Y. 75 00:04:25,320 --> 00:04:28,380 You will be equal to X Y and Z will be nineteen. 76 00:04:28,380 --> 00:04:29,060 Ninety nine. 77 00:04:29,400 --> 00:04:29,850 OK. 78 00:04:30,060 --> 00:04:35,610 And then X will be supplied to brand and Y will be supplied to model and is then will be supplied to 79 00:04:35,610 --> 00:04:37,620 give off object one. 80 00:04:37,710 --> 00:04:44,280 Similarly, when you create a new object or object to broadly be supplied out to here and will stand 81 00:04:44,280 --> 00:04:49,120 will be supplied out of here and 1969 will be supplied out here. 82 00:04:49,140 --> 00:04:55,350 So for that object, number two brand will become for model, become Mustang and it will become is. 83 00:04:55,620 --> 00:04:59,940 Now you are just printing the value shot object one brand then got up to. 84 00:05:00,030 --> 00:05:06,170 01. model God object rendered here, similarly, we are printing out quite a bit to brand more than 85 00:05:06,170 --> 00:05:06,480 any. 86 00:05:06,740 --> 00:05:13,940 So when I was creating the object for that God Glass two objects, vast object the same, these three 87 00:05:13,940 --> 00:05:15,620 values through this construct. 88 00:05:15,890 --> 00:05:17,510 This is now constructed. 89 00:05:17,840 --> 00:05:23,440 So this constructor is having parameters so some constructors, we can create constructors without parameters 90 00:05:23,450 --> 00:05:23,880 also. 91 00:05:24,230 --> 00:05:30,620 So this constructor cannot accept values from main function when we are creating the object that does 92 00:05:30,620 --> 00:05:33,470 that peculiarity of that parameterized constructor. 93 00:05:33,470 --> 00:05:35,420 So this is a parameterized constructor. 94 00:05:35,420 --> 00:05:37,250 So first of all, let's run this program. 95 00:05:37,250 --> 00:05:44,760 Before that, let me compare it to C++ constructors, not CPB down. 96 00:05:44,930 --> 00:05:49,410 No dog-eared or you can predict output, right? 97 00:05:49,490 --> 00:05:53,230 BMW, X5 1999 and Ford Mustang tendencies in it. 98 00:05:53,240 --> 00:05:58,000 So these values start in object number one, and these values start in object number two. 99 00:05:58,300 --> 00:06:07,800 No wonder that Ex-member is if I don't want to send parameters, I can just go like if I want to set 100 00:06:07,800 --> 00:06:12,590 the values without any parameter, I want to set the values by default. 101 00:06:12,770 --> 00:06:16,760 Then I can use a normal constructor without any parameters. 102 00:06:16,760 --> 00:06:19,130 For that, you just need to replace all these things. 103 00:06:19,190 --> 00:06:24,410 You will just define your ancestor like this and you will put that values here. 104 00:06:24,560 --> 00:06:30,860 Branding or BMW, Mortlake or X5 yet equal to 1990. 105 00:06:30,890 --> 00:06:32,530 But like this, or say you can do what? 106 00:06:32,540 --> 00:06:35,890 I'm not showing that right now, we can just skip it. 107 00:06:35,900 --> 00:06:38,870 So that will be an exercise for my students. 108 00:06:38,870 --> 00:06:43,250 You can just have a look at our constructor without parameter. 109 00:06:43,430 --> 00:06:45,900 OK, now let's go to that destructor park. 110 00:06:45,930 --> 00:06:51,320 So regarding the District of Park, you can see here we have a constructor. 111 00:06:51,500 --> 00:06:56,140 Constructor will not have any design and it will be the same thing, right? 112 00:06:56,180 --> 00:06:57,110 Same last name. 113 00:06:57,140 --> 00:07:02,600 Similarly, Destructor will not have any anything, but it is also having the same class name. 114 00:07:02,630 --> 00:07:04,370 But what is there to differentiate? 115 00:07:04,610 --> 00:07:05,770 There is a delay design. 116 00:07:05,780 --> 00:07:09,230 This is that, as you can see this in your keyboard. 117 00:07:09,350 --> 00:07:16,370 OK, now if I'm creating one object like what happened and sector will be invoked and you can display 118 00:07:16,610 --> 00:07:20,630 again even our same values, or you can display anything inside that kind of sector. 119 00:07:20,630 --> 00:07:23,840 So I'm just displaying object is being created. 120 00:07:23,960 --> 00:07:26,750 That will be the something I'm displaying over here. 121 00:07:26,930 --> 00:07:33,290 You know, when the object is deleted after this object is deleted, one happens after the program is 122 00:07:33,290 --> 00:07:36,500 executed and the lander, all objects will be leading. 123 00:07:36,510 --> 00:07:37,250 So then why not? 124 00:07:37,520 --> 00:07:42,800 Our district every week or so, what I'm doing inside the district, inside the district of I am just 125 00:07:42,800 --> 00:07:44,870 printing an object is being deleted. 126 00:07:44,900 --> 00:07:45,310 That's it. 127 00:07:45,320 --> 00:07:49,040 So when the object is being created, the constructor will execute. 128 00:07:49,370 --> 00:07:55,400 And when the object is deleted, the mistake that we executed and the sticker you can set out to, what 129 00:07:55,400 --> 00:08:00,170 are the things you need you get if you want to see something, you can see that if you want to assign 130 00:08:00,170 --> 00:08:03,020 something to something that can alter you, you can do. 131 00:08:03,140 --> 00:08:09,290 But when the program is being cleaned up, there is no point in us saying something to a right. 132 00:08:09,440 --> 00:08:11,660 It's already getting deleted anyway. 133 00:08:11,780 --> 00:08:17,260 If you want to do something at the end of the program, that's where when you use that this time. 134 00:08:17,630 --> 00:08:25,090 And one more point I want to mention you can define functions with a like if that is a violation or 135 00:08:25,100 --> 00:08:30,020 in a class, and you can in two ways you can define it function inside a glass. 136 00:08:30,200 --> 00:08:32,840 That's some like binary we have missed out. 137 00:08:33,200 --> 00:08:38,480 So if you want to define a function connected to a class name, print hello. 138 00:08:38,690 --> 00:08:39,800 Let me do that here. 139 00:08:39,800 --> 00:08:45,200 It says you can have two ways, so I'm creating a public function by Roy Print. 140 00:08:45,620 --> 00:08:46,010 Hello. 141 00:08:46,250 --> 00:08:53,420 See how creating one way of defining that function for this class line will be you can just write that 142 00:08:53,420 --> 00:08:57,960 definition while you define the class that it's in, say, the class itself. 143 00:08:58,160 --> 00:09:03,890 You can, by the definition of the function, my functions definition, for this example, will be very, 144 00:09:03,890 --> 00:09:04,680 very small. 145 00:09:04,910 --> 00:09:05,750 I'm just printing. 146 00:09:05,750 --> 00:09:06,080 Hello. 147 00:09:06,290 --> 00:09:06,680 OK. 148 00:09:06,920 --> 00:09:11,510 That is my video creating a function inside a class, but that is on another way. 149 00:09:11,570 --> 00:09:14,060 So I know that this OK. 150 00:09:14,210 --> 00:09:17,060 You will not write the definition of the functionality at all. 151 00:09:17,060 --> 00:09:17,630 The definition. 152 00:09:17,630 --> 00:09:18,350 We really need it. 153 00:09:18,590 --> 00:09:21,370 We will be really writing the prototype inside the class. 154 00:09:21,410 --> 00:09:24,180 Then after the class definition is all. 155 00:09:24,410 --> 00:09:28,670 You will be engaged in the definition of the function, but that function will still belong to this 156 00:09:28,670 --> 00:09:29,100 class. 157 00:09:29,140 --> 00:09:31,430 So this is a different way of syntax, OK? 158 00:09:31,580 --> 00:09:34,890 That's only the different syntax, which I'm following. 159 00:09:35,090 --> 00:09:36,200 So how are you going to do that? 160 00:09:36,410 --> 00:09:41,210 You can mention the class name and you can put Scarborough Solution Operator. 161 00:09:41,300 --> 00:09:48,770 Then you can print handle menu again defined that function as you do normally, so it will be SEO. 162 00:09:49,010 --> 00:09:54,180 And so this is one point which we have missed, but I have covered it right now. 163 00:09:54,200 --> 00:09:55,400 So what happens? 164 00:09:55,430 --> 00:09:59,870 This function is still belonging to the class line, but it's defined. 165 00:10:00,010 --> 00:10:03,020 I would say the glass, why we are defining it outside the glass. 166 00:10:03,040 --> 00:10:09,880 It's nothing but simplest explanation is if the function is having the lot of lines, if you define 167 00:10:09,880 --> 00:10:13,020 that function inside the glass itself, it will be a habit. 168 00:10:13,090 --> 00:10:17,320 You will not understand anything where the functions start, where the function and where the glass 169 00:10:17,320 --> 00:10:21,700 started and where the glass ends in order to keep the function. 170 00:10:21,700 --> 00:10:25,540 If the function is very huge and it's having a lot of lines. 171 00:10:25,900 --> 00:10:30,730 It will be always better to follow this approach so that the glass can be light. 172 00:10:30,850 --> 00:10:36,870 You can just look into this glass and you can see the variables and functions in that glass. 173 00:10:36,880 --> 00:10:40,180 If that function is having a lot of explanation. 174 00:10:40,450 --> 00:10:43,390 Lot of lines, this glass will be messed up, right? 175 00:10:43,480 --> 00:10:46,510 So that's why we are using this index to access that. 176 00:10:46,750 --> 00:10:47,830 It was OK. 177 00:10:47,860 --> 00:10:49,710 So that's one point I want to highlight. 178 00:10:49,900 --> 00:10:55,210 So now you have two things to note in our number one is our detector. 179 00:10:55,390 --> 00:10:57,370 And another one is our current helmet. 180 00:10:57,640 --> 00:11:05,890 So I'm just calling in Halo Method at the end of the Line Dog panel discarding and I am running that 181 00:11:05,890 --> 00:11:11,930 program G Plus Plus based dark CPD. 182 00:11:12,130 --> 00:11:13,850 So it's not C++ or. 183 00:11:19,200 --> 00:11:23,790 Both gay types specify for clinicians. 184 00:11:24,660 --> 00:11:25,290 What does that? 185 00:11:26,220 --> 00:11:27,660 Lloyd Brown, hello. 186 00:11:28,080 --> 00:11:30,930 Is it because I put that Boyd out here? 187 00:11:31,050 --> 00:11:37,530 Let's see previous thing, which we have been doing that is a small correction order yet, so you can 188 00:11:37,530 --> 00:11:47,140 see why it should be also prefixed before the glass name, before the car like last name and Scarborough 189 00:11:47,180 --> 00:11:48,090 resolution operator. 190 00:11:48,330 --> 00:11:50,640 Then you have to use that function. 191 00:11:50,850 --> 00:11:52,080 So that's the syntax. 192 00:11:52,350 --> 00:11:56,010 So what will be the return type of this function? 193 00:11:56,250 --> 00:11:59,510 It should be also coming up before the class name. 194 00:11:59,580 --> 00:12:00,000 OK. 195 00:12:00,330 --> 00:12:04,290 Then you need to actually go to the compiler program. 196 00:12:04,710 --> 00:12:06,870 Previously, when we have compiled, we got an error. 197 00:12:07,800 --> 00:12:18,870 So and comparing it now that is an IRA, now you can just bring the date see object is being created. 198 00:12:19,830 --> 00:12:21,150 Land of Line six. 199 00:12:21,600 --> 00:12:23,040 Hello, is this planet? 200 00:12:23,040 --> 00:12:29,340 Because I wanted to show that to you how you can define your function outside of class. 201 00:12:30,240 --> 00:12:37,710 Then it's showing object has been deleted and programs and because object is being deleted, is that 202 00:12:37,710 --> 00:12:39,740 the program is cleaning it now. 203 00:12:39,750 --> 00:12:41,490 That is, that is being executed. 204 00:12:42,030 --> 00:12:42,730 So that's it. 205 00:12:43,070 --> 00:12:43,560 Hope you have. 206 00:12:43,560 --> 00:12:48,930 I'm sure this lecture let me turn to that next one.