Object Oriented Programming in C++ : 2020 | Harsh Kajla | Skillshare

Object Oriented Programming in C++ : 2020

Harsh Kajla, SDE-1 at Amazon, Bootcamp Instructor

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
31 Lessons (8h 47m)
    • 1. Introduction to OOPS

      10:21
    • 2. Creating Objects

      24:31
    • 3. Getters and Setters

      14:34
    • 4. Constructors

      19:06
    • 5. Constructor and this keyword

      20:25
    • 6. Copy Constructor

      10:55
    • 7. Copy Assignment Operator and Destructor

      15:29
    • 8. Play with Constructors

      5:16
    • 9. Fraction class

      23:15
    • 10. Fraction class continuation

      9:57
    • 11. Complex Number Class

      6:43
    • 12. Shallow and Deep Copy

      15:03
    • 13. Our Own Copy Constructor

      13:50
    • 14. Initialisation List

      17:25
    • 15. Constant Function

      11:54
    • 16. Static Members

      22:05
    • 17. Operator Overloading 1

      19:46
    • 18. Operator Overloading 2

      30:43
    • 19. Operator Overloading 3

      18:16
    • 20. Dynamic Array Class

      39:55
    • 21. Polymoial Class

      12:57
    • 22. Encapsulation and Abstraction

      11:00
    • 23. Inheritance Introduction

      13:25
    • 24. Inheritance Syntax

      20:06
    • 25. Inheritance Order of Constructor and Destructor Call

      21:34
    • 26. Inheritance Types

      15:41
    • 27. Hybrid Inheritance

      23:04
    • 28. Polymorphism Compile Time

      18:42
    • 29. Polymorphism Run TIme

      13:20
    • 30. Virtual function and Abstract class

      13:21
    • 31. Friend function & Friend class

      14:01
11 students are watching this class

About This Class

Requirements

  • You Should Be Familiar With Basic C++Fundamentals

Welcome to Object Oriented Programming With Python, One single course to start your Object Oriented Journey from Step-by-Step, This course touches each and every important concept of OOPS with it's latest version C++,

OOP is one of the most important concept of programming, It is important because

  1. Makes Visualization easier (Closest to real world scenarios)

  2. Reuse the code, Saves time, Reduce lines of code, Shrinks your project.

  3. Makes code Readable by adding a structure to data with the related methods for this data.

  4. Modularity for easier troubleshooting

  5. Reuse of code through inheritance

  6. Flexibility through Polymorphism

Course will help you to explore about Classes-Object, Abstraction, Encapsulation, Inheritance and Polymorphism.

We will also focus on DRY (Don’t Repeat Yourself) approach to improve our code writing and problem solving skills. Throughout the course you will get tons of Quiz, Sample Codes and Theory material to revise course in a proper format.

After completing this course you will be Industry Level Ready to work as Intern, Fresher or Freelancer and you will also be able to implement everything on your website itself!

Enroll now and I will make sure you learn best about C++ OOPS Concepts

Who this course is for:

  • Anyone who want enhance C++skills by learning the basics of Object Oriented Programming (OOPS)
  • Anyone who want to grasp the concept with real example and quizzes.

Transcripts

1. Introduction to OOPS: hi, everyone. So today we will start on your topic called Oops, object oriented programming. So I get rented. Programming is a programming style that involves classes and objects, glasses and objects. So in this class we will learn the meaning off these totems. Now, let us first understand the meaning off an object. So object is a basic entity that possesses some properties and functions in real world via surrounded with objects everywhere. For example, laptop is an object. Fenders and object table is an object. Jerry's and object. Except we want to involve these objects into other chord because we won't have a court as close as to the real world. Okay, let us first take an example. Suppose we have a student object and let's S Trent has property. Coiled name, property, roll number, A property, Let's say age address property on, let's say contact number. So these are some properties off student object, and we have functions. So what are functions? Functions are the operation that we can perform on object. So let us take an example. We can have a function called change address. We can have a function, several number and so on. Okay, So object Sada basic entities that will have some properties and functions. Now let's go into the deal. Suppose I want to create 20 students. Each student will have some properties. So this student object, we'll have some properties. Let's say currently we have only three properties and no functions. Okay, three property and no function. Name a journal number three properties. And we want to create 20 students. So we will create story in number one. It will have name. It will have a judge and district will have rule number. Similarly, we will have s two name age, girl number s three name, age, roll number and so on. We will create 20 for students. So if we get so if you will create object using this matter. So this is a very hectic method. Okay? It will take us a lot of time. So what? We uses a template called class. So what we will do? We will create our template. So this template we'll have three properties name, rule number and age. Okay. We ever template on this template has three properties name Roland brand age. So over the radio we will create a copy off this template Onda we will name It s one. So we will have name. We will have rule number and we will have each. Now. After creating the copy, we will fill the data. Let's say name is ABC Roll number is 12 ages 23. Okay, so we created a copy and then we will fill their data. Let's say we will create and a copy. The name of this copies as to it will have name It will have rule number on It will have each and now it's time to fill the greater. So let's say name is X rays. Erred Rule number is 24 ages 52. Okay, so this template is called a class and this copy off template, It's called object. Similarly, if we want to create more objects, weaken, we will create a copy. We will have three feels name, rule, number and age and then we will fill their data. Okay, so we have only one class and we can create many objects What we have to do just popular template and fill the data. OK, so this is much, much better as compared to this way. Okay, so and eso if we will create object using this. This is very cumbersome. Mattered because all the objects have the same properties. Name a general number. So it is better to create our template. And this template will be called a class. And then we will make copy and fill later. Okay, so object is make the copy and fill their data make or people data. Okay, Now I hope you goto rough idea so it will become more clear as we go in detail in the future lessons. So I think this is enough territory. Now let us see the cold. How we will create class like to see through a cold. So I have made a file with the name student art See pp. Okay, So for creating a class, we first have to write glass covered and then the name of the class. So the name of the classes student Okay. Opening record closing record on this Simon column. So let's say currently we have only two properties rule number and the second property. Let's say called age. Okay, so this is a way to create a class. This is the Centex for creating a class. Okay, first you ask giver, then name of the class and then the properties. Currently we don't have any functions. Okay, now let's see one more example. So this is a class called product North CPP. Sorry, this is a file called Product or CPP. Let's make a class so glass covered, then name of the class. The name of the glasses. Product opening record closing record and say McCollum. Okay, let's say this product this predict Plus has three properties. First, is I 80 second is Let's take a little bit. And third is Ah, let's according name of the product. So four name we have been. You'd correct already. So correct. Better. Let's say the size is 50. Okay, so we have a class called product. It has three properties, I e. Weed and name, and this doesn't have any functions yet. Okay, so now let us create object. So we will discuss in the next video how to create objects. So for objects. But we have to do we have to make the copy off this bus and then fill the data. Okay, so that doesn't device. So what is the class? Glass is basically a blueprint. Glasses are blueprint. Let's take one more example. Let's say we have a glass coiled card. Okay, Glass car. So this car template this class blueprint, let's say, have four properties. Ah, name more than number. Let's say price and number of suits. Okay, so glasses a blueprint? No, we will make a copy. See one. No, we will have all the properties. Name Morley number, price and suits number off suits. And now it's time to fill the data. Okay, so let's the name is ABC. Moral number 234 Price. Let's say 2020 k and seriously see yourself for Okay, So this blueprint glass is a blueprint, so blueprint doesn't have data. Okay? These are empathy. They are just the name of the fields there. Only names there do not contain any data. If you want to fill aerator, what they will do, we will make the copy of the template. Then we will have all the fields, all the properties, and then we will fill data. So objects are real. World the area while they are created after filling after filling the fields. Okay, so this is I always remember class using a blueprint. Glass is a blueprint or a template and objects are really boils. We will make the copy of the template and then we will fill the data. Okay, So in the next video, they will learn how to create the objects. Okay. In the next, really, we will learn how to create objects off class called product and objects off glass. Cold student. Okay. Thank you. 2. Creating Objects: Hello, everyone. So in the last video, the started discussing about hoops we learned what is Oops. Object oriented programming avatar object and how we can create classes. So in this video we will see how to create objects and how to access its properties. So in the last radio, we created this class and they know how to create classes. So now let's see how to create object off this class. So when we right. So when we right and a is the name of the variable and A is off type in feature. Now we have a glass student. This trend has two properties age and William. But now I want to create object s one. Now I want to create a student or I can say I want to create a variable s one off type student. How can we say that? Because glasses nothing but I user defined data type the another name of classes, user defined data type. For example in the belly float. These all are built into the types building. There types varies. Glass is a user defined data type. Okay, so when we right and a is a name off the variable But when we right student s one s one is a name of the object hair. We will call it a variable on Dhere. We will call it a object. A is off type in. Teacher s one is off type student. Okay, so student class glasses, nothing better User defined data type. So let's see, when we write nt what will happen? We will get four blocks off memory space. And the name of this block is a okay and there will be random values, random garbage value. So when we write student s one, we will get a memory block. The name of this Bacchus s one and vital birth size. So student contained two in teachers rule number and age both are far four bites. So in total eight bites. So the size off this block will be approximately eight bytes. Not exactly. It bites because there are many other things. Also, we do not need to understand them yet. Okay, so this is near leered by its approximately eight bites. But not exactly It bites so as soon will contain age. And it will have rule number and garbage values OK? Similar. When? Right and there was garbage we lose so similarly. When we create an object, they will be garbage values Similarly we can create and a destroyed int student s too again we will get approximately eight bytes of memory space Name is s two age and rule number and similarly garbage value. Okay, so still No. We have created objects statically alone. We are creating objects strategy early But we can also create objects dynamically So in a static how we create objects tragically and a okay student s win student s to So what will happen Like student as one is it is containing age and rule number garbage values. So why garbage values? Because we are not starting the properties ourselves till now. That's why garbage values similarly for student too. Age rule number, God based values. Okay, Now let's see how we can create objects dynamically So for creating an interior dynamically this indexes and to start a new. And so this is this index for creating an indigent dynamically. So what will happen in the heap memory? We will get four bytes of memory space and in the static memory, this is the name of the variable E on If it's air does is 100 then 100 will be here. Okay, so this is started Memory on this one is heap. Similarly, if we want to create an object dynamically, the Centex will be similar to this one. We were right student. Then start Ste is new Gifford and then the deter type, which is student. So what will happen in the heat memory? We will get nearly eight bites and this will have a judge rule number, garbage value and in the start, in the static memory, we will get it bites off memory space because as today's appoint a similarly the size off A's eared bites because it's a pointer and let's say for geneticist rendered So this will contain 300. Okay, this will contented ended. Okay, so what? We used to remove it Variables we can also do with objects. Now let's see in good. So let's create object statically so we can create many objects. Student As to similarly, we can clear to many objects in one line like we used to do with variables. So s tree as food as five and so on. Now let's create object dynamically to creating objects dynamically So this index is quite similar. So students start as six is new, Gifford and then later type, which is student. Okay, Now let's see how we can set the property off an object. Okay, so we haven't object. S one s one. Contain age and rule number and garbage produce. Similarly, we have object as to age rule number, garbage value and let's take when dynamic object. So this is SD now this is sour. He memory on Dhere. We have age and who number which contain garbage values. Okay, so when we write and here what will happen? We will get four bytes of memory space Now If you want to put something inside this box, what they will do, we will, right? A equals five So five will come here now. Similarly If I want to write something here, what I can do s one equals 24 now. Is it right or wrong? It is wrong because s one contain multiple properties. If I want to certain each the Centex will be s one dart age equals 24 now This is right. So 24 will come here. This rally will become 24. Similarly I can settle. Number s one dot Rule number is let's 100 so this value will become 100. Okay, So certain Texas Very simply. So what we have to write. This is object name dot Property name. Okay. Object name Dart property name Now, Lord, seeing gored aspirin, dart age. Let's say 24 s when Dart rule number. Let's say 100. And similarly, we can also print See out as far north age. See out it's on dirt. William Byrd. Okay, so this is a very simple semantics to excess the properties of an object. Now let us talk about how to excess properties off a dynamically created object. So we have object six, which is dynamically created. Study it. Wait a second. Okay, So if we have a major very well, which is dynamic created. So what? We'll do the situation and start a is new. And so this is it Bites pointed on. This is our four bites memory space. So we cannot write Simply equals five. This is wrong. The right way to do is first. We have to reach this box now for reaching this box. We will lose our star r D defense operator. So star is five now, five will come here Similarly, in case off, then immigrated Object. We will do something similar to this. So we have object as six, which is dynamically created so as six is no student. Okay, so this is Ah, point off it bites. And now this box contains age and the lumber which are garbage initially. Okay, so we cannot write a six dotage. This is wrong. What it will do is it will goto a six on inside a six. It will try to find a judge. But age is present in this box. Ages President in this box. So we have to teach this box for it. In this box, we will use three d reference operator. So Star Essex, by doing started six We have reached this at this box. Dark age. Let's a Fife now. FIFA will come here similarly Start as six daughter lumber. Let's it 200. So 200 will come here. Okay, so in case offered dynamically created objects, we have to use the reference operator to reach this box. Okay, so let's see in court, we have to use start operator, so star at six Nord age 23 a six. Doctoral numbers. That's a 30. Okay, now this is critic. No, we have No. We also have a shortcut to do this. But we were right at six. At our age is during the tree at six. A total number is turkey. Okay, so these two lines and these two lanes, they are exactly seem exactly same means, if you will right, start as six dotage and we will write a six dark age SX average. So these two are exactly same. This ad was a short curt. Okay, this is a shortcut. They will exactly works him. But this is a shortcut. Many people use arrow instead off using star and then dart, and then records and all that stuff. It is much simpler to use arrow. Okay, No. If we will run this file, we will get lot off others. Let's see why. Okay, So I'm telling you, if we will run this file, we will get a lot of feathers. So let's see. So we are getting a compilation edited on Let's see that it So this is that it ages Private rule number is private Ages private again. You just played. So we're getting something. So we're getting another Which is telling us that age, Roland. But these are private. Now, let's see what is private. So these are concept in hopes called excess modifiers exists. Modifies so access. More defiance is, ah, who all can access the properties and functions of a class. Okay, so there are three types off excess modifier, public, private, and the tournament is predicted, so we will not discuss about protector yet. We will discuss about public and private. So what private sales is private will say you can excess properties of a class inside the class only. Okay, so Private says you can access the properties only inside the class. What we're doing here is see age and the lumber can only be exist within student class lettuce. Between this record and this record, right, we'll see this two fields rule number and age can only be exist within the student class. That is between this record and this bracket. Okay, What public says is if the access modify this public, then you can use the properties of the class anywhere, anywhere in your program. You can use the properties of the class. Whereas if the access modified his private, you can use the properties inside the class only. So here vindicated these two variables. These two properties, we have not defined any excess modifier. So by before, the access modifier is private. Okay, so default excess more than fire is private. If you will not specify the excess modifier before it will be private. So here rule number and age by default their private And what I'm doing here is See, I am using excess. I'm using each and roll number outside the class in the main function. I am using each and roll number. That's why we are getting a compile ation error, which is saying they're true. Lumber and age are private, and it cannot use them outside the class similarly via using a general number here. Okay, so what we have to do if if I want to use the properties of the class outside the class, we have to make them public so for public. But we will do. There's a very simple Syntex. We just have to write the keyword public. So, uh, we will use we will write the giver public and then call them So after eating public column , what will happen? So after reading public everything, everything below public will become public. So now, roll number and age, the air public. And now this line is correct. This line is correct. Basically, we will not get any any comm violation error. Okay, now let's see. It's combined our program. So we are getting better here. So what is the other? Okay, this vectored? That's right. No, see, our program is running. Okay, now, what if I make in Teacher H private? So drive it now. What will happen? No. So when you read public, everything inside public will become public. So there's real embarrassed public. But now we have to find another access modify, which is private. So now ages private. So it can only be used between this and this. Beckett, that is, Each can only be used inside class. And the lumber can be used anywhere. So, uh, as friend or ages 24 this line is correct because Sorry, this line is wrong, because ages private. But this line is correct. Why? Because it is a public role. Number is public, ages private. So we will get compile a Shinn editor. Wherever we have used each outside the class, let's come by level problem. Not this time. If you will see that er that there will be only due to each ages Private ages, private ages, private. There will be no other regarding the role number. Okay, so this way we can use like we can define multiple excess modifiers. Okay, Now I want to show you one more thing. Let's remove discord. Okay. Ah, let's move everything else. - Okay , so what I did there is I am created. Oclock are catered. A fine student used art, See pp And this is our world class which is containing the class only now why I'm doing this is see days a concept in software development which is called isolation off logic. So overt I solution off logic seizes Whenever you want to create a class, create a class in a separate file, so we will have a file. Now, this file will create the class and we will have another file in this file. We will use this class us glass here. Okay, so it's like best practice in the software. His in the software industry, because the logic is different here where Harry will just defined the class. And here we will use class. So I did exactly the same. Okay, so I have a class which is student and I have ended the class and I have another file store in the U start. CPB here. We're using the student class. Now if I will run this program, it will through me and edit, but will be data it will see. I don't know what this student by because student is defined in a separate file. So if I want to use student in this file, but what I have to use I have to include that file in this in this current file. So hashing Plourde degenerate commas. Name of the file student art See pp. Okay, Now this is correct. Now let's hear now alerts another program. Okay, so this is trying me at it. Ah, what is the original? Let me see. And fund and private. Oh, after a in this class also. Now, this is not This will be correct. See, It is ending, though. Okay? So always, this is the good practice. May class in separate file and you start class in your current file? No. Now, when we included I esteem class, I used this arrows for the ustream. But when I used But when I included student file, I used devoted comus because for four billion files the files which are already present we have to use these arrows. But if we create a fly file on our own, that is user file the file that we have created. We have to use double brackets. Okay, This is justice Syntex. Nothing else. Okay, so thank you. 3. Getters and Setters: Hello, everyone. So in this video we will discuss some more concepts off object oriented programming. So in the last radio were discussed about excess more device. We know how publican private affected the accessibility of the properties of the class. So vacated this class in the last video. It has two properties, rule number and age, Remember, is public and ages private. So let's say one more function. So this class and let's make that function public. So I have a public function. The name of the function is, let's say, display. So what dysfunction will do is it will print the agent serial number of the student. So I returned. Type will be void, see out age space and William. But so dysfunction displaced the age and rule number of the student returned. I will be void. Okay, now let's discuss how to call this function. So we will call this function using the dot operator. Just as we use dot operator toe access the properties we can use dart operator toe Xs or to call the function. So for property we're too used to do is object name Dart property name for calling a function object named art function name. Okay, So yes, one. So s one dart. What is the name of the function display? And so nor display similarly, we can call s to dart display and let's go on display Function for a successful start a six not display. Okay, Andi leads straight short, but also for the six. So a six Eddo basically. And that's all. Okay, so this is the way to call a function now. Our function is not taking any argument. If our function takes argument, we can pass it in parentis is since our function doesn't take any argument, Our parentis is are empty. Okay, so no, what I want to do is ah I want to use this age property outside the class. This is properties private. So my question is how to exist a private property outside the class. So we'll dance. It is using a function. So let's make of one more public function. Ah written I will be in danger on the name of the function is get h So this is a public function. What dysfunction will do is it will return age Age is a private property. So what is happening now? Here is See this get age function is a public function. So since this is a public function, we can call it from the other file that is, from the student used art CPP. So we can call this function and this get its function. Willard Anna's age were s age is a private. Okay, So with the help of this public function, we can get the value off private function. Now, let's see in cold. So this is our file. What I want to do is ah, see out. As for an age s friend, art will call the function, get egx get age is a public function. So no compilation and I will be there. And similarly, let's do it for us to Israel. So see out as to age Esther Dart. Get it? Okay, let's add and lane here, Okay? Everything seems fine now, So one more thing. Ah, we can only access the edge. We cannot set age. So if you will run this program, we will get compilation editors saying that this is properties private, so you cannot access them. So let's make let's commander it out. Age Onda age. Okay, so, no, I would program will run. Fine. Okay, so let's right now. I put him. Okay, So the senator is friend art display. What is the others? Last warrant has no member named display. Oh. Ah, We also have to rent this file because with your genius to this file. So this vulture also willing not ah see out age and no lumber or his data as si or it was not declared in this scope. So the other is this See out the function idea That's the oldest defined in io stream file . So I have to include I a stream here again at it. Okay, so this airline is defined in names, fees, so name space est. Really? No, this is fine. Let's in this file. So ages private. Okay, so we also have to commend it out here. Andi also, we have to commend it out, and it is. This seems fine. Okay, So lead sprint. Let's get days for a six. Also, soc out a six. His six dart get age. I think everything is fine. No, let's turn our program. Let's run this. And now we will run this a six year dynamic. So for dynamic, we have to use the reference operator. And now let's in this file. It seems like everything is running fine. Okay, so that doesn't realize the output. So first of all, we call the display function, so display function will print the age and the rule number. So this is the age which is a random value because we have not set it. And this is under because we certainly number Toby 100. Okay, so after s one rep rent s too. So far. Esto. Where did insert any values aboard? The values are garbage. And then we are getting that each person, that is for a soonest, this it is random value because it is a private field and we have not make off public function to set it similarly as to wages also. Ah, garbage value. Because we haven't started aan den a son, daughter lumber which we said Toby 100. And after that exit. So we said the rule number for a six and a $6 display so forward as six the ages a random value and the rule number is 30 because it said it. Then again, with six, then again display function. So both are same and then regard the age for a six. So each four and six is a random value. Okay, so the output is expected. Output is what we expected. So instead off, like using their the difference Operator. And the daughter operator began directly right. A six headed wage. Yeah, it's working fine. Okay, so So now I can read the property of a private field. So if I can read it, then they should also be Abie to read it. So for reading the so for writing the private property What we can do is we can create a function, avoid said age. So this certain dysfunction will take ages input and it really sit age to a and that's all . Okay, so let's come to this class So this classes like we will get confused using this class. So I created a new class student New Dart CPP. So now we will do the work here. So for doing something, first of all, you have to create object. So let's create to object. One is starting and other one is dynamic. So the story and win Now let's create our dynamic object student as to new student. So for this student a work. We also have to include the file here, So hash include student hard to see pp. Okay, So Knowledge's said that age and then we will display So yes, when dart certain age. Oh, now let's say ah savage. And let's say the value is 20. Similarly, for esto as to every wage. So the s Tuero surge and let's say 30. Now let's call asunder display and s to a religiously Okay, so now there doesn't know I program So Western Dart set Ege There's something wrong with it classroom and has no member set age. I again did the same mistake I have during this file because I did changes to this file. So this green line means that these many lember off lines are already compiled and this yellow lines means the area to become pile. So court blocks is so cord locks also help us. So now when you will render program, this whole cord will become green. See? Now everything is compiled. No, it will work. It will not through any other. So ages 20 and the real number is garbage value. A just 30 total number is a garbage value. So in this view, we can like we can get the property and we can also set the property. Okay, a private property. So one question that will be coming to her mind is what is the use off making each a private field? If you can read and write it, then basically, what did we achieved by making it private? What is the reason for making something private? So look carefully. We cannot change the edge directly because it's a private field. But we have to call a function, get it or certain age, toe xs the private property age. Okay, so now let's take an example to illustrate you the benefit off private. Let's I want to put the constraint on each. That is cannot be negative. If each would have been public than anyone can set it to B minus one. How s rendered? Age equals minus one. And it would have been broke if the is was public. But now the ages private. So I can put a constraint here before starting the age. But I will do I will check if the input is less than zero. Then simply there. Done. Don't do anything. Simply return we're not setting VAHJ. Okay? So we can add constraint like this. So this is the use off private property. But we will do We will make a public function to excess the private property. So now here we can add constraint, for example, like if you want to add more constraint like there should be a password, you have to give password as well for certain age basically and all traced person can a no trace person can only said age. So let's say the password is went to three. So if Pastor it is no articles to 123 If passer is not 123 then don't do anything. Simply return. Okay, so now regard the property toe, add the constraint. We get the power toe er the constraint so I can add multiple constraints here. So whenever you're working in a reliable project, if a property is important, that is, 1/3 person should not be allowed to change the property. So we should make those properties private. Okay, so this is a get function. This is a search function. Get function. We can read. And with the help of cell function, we can write so originally, call it. Get her function and certain function getter and setter. With the help of greater function, we will get the data With the help of 30 function. Begin said the data. Okay. Thank you. 4. Constructors: Hello, everyone. So today we will learn about constructors. Before starting today's video, I want to cover two more things that I forgot took over in the last radio. So the first thing is, See, we have public, private and then again public. So this whole court belongs to public. This court belongs to public so we can write. We can write this score in a better way in a better manner. So our talk to Messi scored. First of all, let's remove indoor lemur from here and put it in the public section and let's remove this lane. Eso no the right public on liver in time and similarly, there's no need to write private way. Let me show you. See, this age is private by because there is no excess modifier defined above it. So by default, excess modifier is private, so there's no need to write private and similarly in the previous core public was returned two times but hair publicas but Harry Reid public only one time. Okay, so this court is much better. Earlier, it was like public public and then private and then again public. So this doesn't seem right to me. The sun is much better. We are using. We're using the properties. What property first were using their default property that default this private. So there is no need to read private and we're writing public on livings. Okay. Second thing that I want to cover is how display function can access each and remember, see roll number is public, so remember can be exist anywhere in the program but ages private since ages private. It can only be exist within this class, and display function is defined within this class, so display function can access each. Similarly gutted function can also access age because God, its function is also defined in the student class. And similarly, Saturday's function can also access private variable each because this function is also defined in with Indy class. So these are the two things that I want to look over in the last radio. But I forgot to cover. Okay, now let's start with today's topic. So till now we have learned how to create classes, how to create objects of a class and how to excess properties of the objects and excess modifiers. Let's see what our constructors and how to use them so when we right student s when what will happen? Rule number, age and we get a garbage values in these wheels. Okay, So if every US and our display this too will get printed Fine. Now let's analyze this statement. There's analyze the student properly What will happen so this internally and repairs in this way as soon Dart student. And generally this statement will be executed in this fashion s friend Art student So what is the meaning off? That's an art student So we can see here Student is a function just like display Strength is a function just like the display and as an object is calling that function. But this function name is Seema his last name. The name off other classes student and the name of the function is also student. So the function name is Seamus Class name. So this function is called constructor. This function is called constructor. So what is the purpose of a constructor? So it will do one simple thing. It will initialize the data member or the properties with the garbage values. Okay, So properties and in the name of properties are deter members did remember Okay, so over dis constructive Alu. It will initialize the data member or we can say the properties off the object with garbage values. So that's why these two properties are initialized with the garbage values. Because this is the work of dysfunction. So constructor function has some special properties, so construct pays a special function. Now let us right some of its properties. First, its name will be Seamus Class Name. So the same name as the name of the class. Second, this function has no return type. Tired property is no input argument, No input argument. So these are the properties off a constructor or we can say default. Constructor, These are some of the properties of the default constructor. Okay, so let's analyzer to Baltimore. So I am saying when we right student s win, the statement intimately will be interpreted as s when Dart student object name Dart function name. So now the question is heavy. Creator dysfunction No, we have not created this A student function in our class. But this function is being called and our properties are initialized for their default values. That is the garbage values. So what happened is so s own is we create a class constructors automatically created. So we do not need to create it. So we can use this and build constructor to initialize the properties off our objects. OK, so they get certified constructor. As soon as we create a class, we can also create constructor on our own. We will see in some time how to create our own constructor. Okay, so now let's see how the inbuilt constructed look like So I told you there are some properties. First they will be northern type, so empty and then the name of the function will be saying now the name of the constructor will be seen Mystic last name. So that last name is a student. So name of the function is student No input argument and similarly, it will not it on anything Northern type, no argument and same name as the class name. In fact, we can remove that remote. Okay. And also this. Okay, So this is the default constructor. The fall construct ever looked like this. So what are the properties of the foil constructor? Same name as the class name. No input argument and no return type. So s illness. We create an object this function or we can say this construct table because for every object we create, constructive will be called. So what is the purpose of a constructor? So the purpose of a constructor the work off a constructor is it initialized? The object initialize the object or we can say it. Initialize is the property often object with their default values with the garbage values. Okay, so for every object constructed will be called on livings in the lifetime of the object. So when it will be called, it will be called at the time of creation of the object. Okay, let's see some examples. Then you will understand it better if I write student Yes one. Then this function will be called. If I will write student s too. Then this function will be called Even if I create dynamic object students start history is new, student. Then this function will be called So basically the constructor will be coiled on Leavins in the lifetime of the object at the time of the creation of the object. Okay. And how all this statement will be interpreted internally. So this is same as s one dot student and this is is to dart student so internally these statement will be interpreted like this. And how will the statement will be interpreted internally? Star s tree dot function name, student or we can say s three adult student. Okay, so now let's see in cold. Let's make a constructor. Let's make defiled Constructor. So the function name will be same as the class name Last name is student so function name will also be student They will be no input argument and that's all. So this is our defiled constructor. Okay now internal constructor Well look exactly like this No one important thing is as soon as we create our own constructor, the internal constructor is no longer available to us So this is the constructor that we have created. So as soon as we create our own constructor, internal constructor is no longer available to us. So now if we will create object than our constructive will be called Internal constructor will largely called because it is not there. Okay, so our constructive will do the same book as the internal constructor was doing. That is it will initialize every property of the object toward default value. Okay, now Let's see. Let's start some statements here. A prince statement Soc out! Construct a guard. Okay, now let us. I could hear some objects here. So student s one storing best win. What will happen as soon is this object is created. It will call the constructor that we have created and Democrats have is not available because vacated our own constructor. Now let's call the function display What this play function will go. It will paint the agent the rule number. And since the agent roll number, we have not set ourselves, they both contain garbage values. Similarly, let's create another object student s too. And let's call the display function. Now let's create our dynamic object So sarin star s tree as new student and let's call the display function. Okay, So what will with our s o? If I had run this file, What will be our output? First I get did this object. So what will happen constructively called So Alfred will be construct a cold and then display function will print the age and the rule number. Both are garbage so garbage with garbage value. Then then the concept of will be called for object esto so output will be constructor called and then it will print. The garbage will lose each in their own number. Both are garbage and similarly for this constructor called and garbage value off each garbage. Really awful number. So this is our expected output. Now let's see where Juliet output. So first we have to run this file. Now we will win this file. Now you can see the output Constructor called for object s one. Then the barb Israelis off a general number constructor cold for object as to garbage. Really off a general number Constructor called for dynamic object history and the garbage values off a general number. Okay, so whenever we create objects and build, constructive will be called. But if we create our own constructor than our constructive will be called and internal constructor will vanish and barrel constructed will go away as soon as because as soon as we create our own constructor. Okay. So we can create many constructors for example Ah, this is a default constrictor. Let's create a perimeter ize constructor. So betterment based constructor So as the name suggest this Construct, renovate, take arguments. This constructor will take parameters as input. So function name will be seen as the classroom which is student and let's say they can put remember And what it does is it will a signed all number to the perimeter. And let's write a brand statement. So see out last Chapter two, Constructor Dugard. So So if you will create. So if we will create object with no perimeters than this function will be called Discuss tractable Bacall. And if we will create object with one perimeter than this function will be called. Okay, let's take an example Toe, Understand it better. So if I will write student s for what will happen that the fall constructive will be called because there are no perimeters. But if I write if I pass a perimeter student s four a perimeter 10 now what will happen, paramilitaries Constructive will be called See when I write student, as for it will be interpreted as as four dot student. And this student is default Constructor, that we have defined a default constructor. But I want to call Fatima. Traced constructor. So for perimeter raced constructor, I have to pass one perimeter, which is then we have to pass an interior perimeter. So this land will be interpreted as as four dot student and then Okay, now, this time, madam embraced constructor will be called. Okay, so this is the concept off function over lording we have covered functional lording earlier . This is seem This is same as the concept of functional lording. We have two functions bird one function doesn't take an import. Any perimeter is in port on the second function Take when intelligent argument as input. So these two are different. Okay, So as for door display now lives in our program. Okay, so we have to horrendous file first. And now we will win this fight. See constructor Too cold for object as for constructor to is being getting called and as photo display Print age and the rule number. So roll number is 10 because we set it and ages are garbage value. Okay, let's see it again. See out. Fatima tries to construct their demo. Now leads in this file. See Fatima days to construct their demo constructor to call because it past one input variant Egypt argument as input and rule number is ages of garbage value a Roland Burris 10 by 10 Because they said Rule number toe bitten. Okay, similarly weaken Great dynamic Object says Well so Student star s five is a new student and we have to pass an indigent argument So 20 it's faith not display. Okay Saudi As for a federal display So constructor toe coiled the value off Age is a garbage value and the value over a number is 20. So so for one object Onley one constructive will be called It will never happen Did default and Barometric Constructor Both are being getting called Know if there is one object only one constructive will be called on Lee at the time of the creation of the object constructive will be called on Lee at the time of the creation of the object. Okay, so this is very important for every object. One constructive will be called on Lee at the time of the creation of the object. Okay, so we will learn more about constructor in the next radio. Thank you 5. Constructor and this keyword: Hello, everyone So internalization, We will continue our discussion on constructor and we will also learn one more thing which is called discovered. Okay, so let's start with your decision. So let's aired of one more constructive One more paramount priced constructor. Now, this time this perimeter ice construct people take two parameters h and remember Okay, a general number. So property age is perimeter age and property Row number is the batter material number. Okay, let's add one prince statement also So see out constricted three chord. Okay, So what will happen now if I will create an object with two parameters So student as 62 parameters panel under the value off a general number and what will happen So this will be interpreted as a six dot student 10 and 100 So which construct level But which construct rate will be calling So constructor number three will be called because this is matching constructor. Okay, so construct them. But they will be called. So if I write a six yard display now our age and got an hour, a general number there do not continue in garbage values. It just simply 10 and rule number is 100 okay. This time did not contain any garbage values. Now let's see. So let's create a student object student a six. And in order to call construct a tree, we have to pass to arguments, age and rule number. And let's call the display function so as $6 display. Okay, so we have to run this file first, make positive changes to this file. And now we will win this fight. So constructed three cold Okay, then. And 100 this time Needed age in order. Rule number contain garbage value. 10 is the age hundreds d number. Okay, so tell me what will happen if I like? If I commend out the default constructor So let's commend out that before constructor. Now what do you think? What will happen? Okay, so as soon as we create any constructor whether this defaulter Param it placed then the inbuilt constructor is not available to us anymore, Okay? And build constructor is not available to us anymore. So at this point of time, I have only two constructors and both the constructor are Fatima traced constructors. Ok, so student s win this land will through a center student s to this land will also through a center and similarly store industry, this land will also through a set of way because and then deliver type lenses. How This is how this line is interpreted it recall as soon Dart student. So it is trying to call a constructor with no arguments. And in this file and instrumental sippy file are do not have any constructor with zero perimeters with zero arguments So I will get another are saying like matching constructor nor phoned something like this matching constructed north found or better can be like something like this We cannot initialize s one can not initialize s one. Why? Because the concept is not dear. Okay, Construct is not there. So as soon is we create our own constructor. The Ford Constructor vanishes before constructor goes away. Okay, Now let's see that it Okay, So why this is running Because after doing changes to this file after committing commenting it out I didn't run this file so first we will run this file okay and no run this way. So I go ordinated and you can see that So no matching function for call student student. Okay, so this is the area that we have discussed it cannot find it is not able to find the function. Okay, now let's experiment with one more thing. So what will happen if I, like, change the perimeter named Toe property name? So let's make it all number. And let's also make it through number. So the perimeter name is Seamus to proper title number. Okay. Perimeter rule number is same as the property room number. They both have the same name. So what will happen at this land were Do think what will happen. Okay, so you understand what will happen. We have to go back to the class off scope of a variable. So if you remember school for her variable, let's take an example to understand I have this small cord and based in if a bigger than five go inside the loop, create another variable with the same name. Let's initialize it with one. And now let us try to print the value fee. So according to me, output will be one output off. This land will be when Webvan because at this lane would come by level. Do compiler will try to find the closest a compiler will try to find the closest. Which one is the closest? This one is the closest at this lane. I have to Is I have to. Is this one? And this 12 ways are visible at this line. But combine level. Try to find the closest one. Since this is the closest one or put will be even. Okay. Now see here. Rule number at this lane. I have to roll numbers. I have to row numbers to roll. Numbers are visible at this line. 1st 1 is barometric rule number and the 2nd 1 is property roll number. So what do you think? Visual number Compiler considered. I think the perimeter one. Why? Because this is close. This is close. The property rule number is like defined above. Okay, property really embrace to find about. So this rule number is the closest. So at this land, what will happen? Put the very off little roll number in tow. Roll number. So basically this line means nothing not reserved a zero not reserved a zero. This line is like absolutely doing the thing. Ok, so now what I want is I'll but him Our aim is very simple. We want this wonder number Toby Perimeter Rule number and this rule number Toby Property, Remember? So this is our simply now how we can achieve it. Okay, How can we achieve it? So there are two methods to achieve this. So let us discuss both Dimitar's. So the first batteries make a rule number are again. So it was our make it arigon makers Arigon So if the names are different if the name off the property and the parameters name are different than there is no confusion at all. But now let's come to the second keys. I want this to be real number only. That is I want property. Name is same s parameters name now how we can achieve our him so we can achieve our aim with the help off this covered with the help off this keyword. Now what is a discovered? So this holds the address off the current object Horthy address off the current object. Okay, so I think point there holds memory or this is we have discussed pointers and we know pointers holds memory Does is this is also holding the address. Where does it mean it means this is a pointer variable This giver. It is a point of everybody. Okay, This give it is a point of variable every function of the class. This is a function. This is a function constructs also function. But it is a special function. This is also function. This is also a function. This is also function. Okay, so every function off the class every function off glass have access to discovered every function Have this giver off on their own off their own. Okay, Now let's see. How can we tell you about him with the help of discovered? So what? This work this giver used to do is call this one, but I will do. I will create a student s red one parameter that certain so this constructive will be called now What happens is I will get age. I really get rule number and name is s. And let's say the others off. This memory block is 700. So dysfunction the student the student function have discovered so the student will contain a student. This will contain 700. Okay, it will contain 700. Okay, now let's deep dive how this can be used. So see when dysfunction is getting cold when discussed. Replace being called what it is doing but the value off a into age. But whose age Who's objects age? Okay, who's objects? Age? There are multiple objects we have. We have created many objects, but whose s one s two s three. Whose whose age I am, refering toe. Okay, So what happened is whenever you call whenever you call a function of the class, you passed the address of the object to the function. Let me let let us understand with the help of an example. Okay, So whenever I create an object that's a created object s with two parameters 10 and 100. So what dysfunction will do? This function will call this constrictor constrictor number to imagine constructor. Okay. And let's say this is each and this one is rule number and the address is 700. So this student function have discovered. Now this giver will contain 700 by 700. Because when this is when this call is when this call is there, it passes 700. It passes the object, it passes the address of the object. So 700 is being passed. So that's why 700 will get stored in this Pointed No. When I do so at this line, what I'm doing age equals a put the value off a in each. But whose age How do I know whose age this each this is with the help of this, I can be reference that I am talking about s when I'm talking about Yes. So this each so equal say implicitly this implicitly It is interpreted as this Andrew each is a Okay, so this contains 700. So 700 aero age is a is a really off a or 10. Similarly, this a roll number is containing 100. Okay, this is Seamus started this dart age. Is he okay? So this is how it works. So whenever object calls a function, it will pass. It will give the function. It's address and data dressed will be stored in that this giver off that function. Okay, so this is how it works. Okay, so now they're just now let us see in cold. Let us try toe print the valley off this what this contains. Okay, So which construct racially or get so let's first command out. Everything so delivered. So to avoid confusion so I'm commending out everything. Toe a word. Confusion. Now let us create some objects. Okay? I am creating object s one. Now let's say it contains two parameters age and the rule number. Now let us bring to the adverse affects one soc out. She ordered us off this one. How we can get there. There's off this one using the address operator. So where does Office one? Okay, so it will call this one This constructor. Now, this constructor has access to this Gifford. So the address off s so that the surface one will be stored in discovered. This is appointed a point available. So this and and Lane Okay, let's on this file. Now let us also in this file, see address off s one is this one. And this also contains the same address. Okay, so this will contain this is containing their days off s one. Similarly, if we will create more objects, I am grating. One more object. Let's call it s too and lets it. The values are 20 and one red. Let us spend the at the sophistry. Now that doesn't decide so. And Joseph s one, this water same and Joseph esto and their dress off esto. Isn't this this point? Very well. Okay, So I hope you on district the point. Whenever object calls a function, it will pass its address. And here in this function, data address will be stored in the variable This in the fevered This Okay, so a j will say this implicitly is in the better It is this aero age, but using this is optional using this is optional. Okay. Similarly, using this is option for hair. Also here also using this option. You can use this or if you don't want to use, then don't use it. It is optional here, but in this case, C in this case, where the perimeter name is same as the property name here it is mandatory for us to use this operator to use this giver. Sorry. So here it is mandatory. Here it is mandatory to use this white is mandatory because we have to differentiate between the perimeter roll number and the property roll number. Okay, so how we will call this function, it will create an object student is with one perimeter alert certain so the lumber is containing 10. This function will be called and let states air doses are 200. So I heard memory block with s age and remember and it's address is 200. Soto wondered, is being passed. These 200 will be stored in this giver off. This functions of this contains 200. So what I'm doing here Is this a roll number is para meters rule number. So parameters roll number is then and this era room this me this this is containing 7 200 Soto wondered A rule number is Ben. Okay, so this is how it works. I hope you haven't destroyed everything. Okay, so what we learned in the two day session. So we learned what? Our constructors. We learned how they are created automatically how they're called automatically. With every class we get a default constructor for free. How can we create our one constructor with different perimeters? And at last we see what is this giver it and how to use it. Okay. Okay. So one more thing that I want to cover is suppose I want to add a constraint. I won't do Add a constraint word constant. I want every object I want Property age should not contain garbage value. Property age should not contain any garbage value. So how can achieve this goal? How can I add this constraint on the object? So what I will do? I will write a paramour traced constructor just like this one. So I will write. Obama tries constructor So student, this better. More discounts of people take ages. Input on this will do Age equals a So s Inez. I created this perimeter Traced constructor, as soon as I created this perimeter is constructor. The Ford constructor is no longer available. The four constructor goes away. It is not there. Okay, So whenever a person wants to create the object off student class but it will do first awful. It will try to do student s But this will through other violated because there is no matching function. No matching constructor will be there. Okay, there's no matching constructor. And similarly, if you will try to pass pooper two arguments let's say 10 and 100. This will also through a center because there are no match in constructor. So ultimately, if he wants to create object off student class, he has to give one value. He has to give one in teacher value as perimeter. And this individual value will call this perimeters constructor. And this is the age will be said. Two days will be set to 10. Okay, so in this way, my property age cannot contain a garbage value. Okay, So for creating the object of student class, the user have to give one. Indeed. Your argument. Okay, so this is how we can air constraints. Okay? How? We're able to wear constraints, because as soon as we create any constructor, any whether this paramour tries or default or any other type of question for this default constructor is no longer available. Since this default construct is no longer available, this statement is not valid. Any mood. Okay, so I hope everything is fine, so thank you. 6. Copy Constructor: Hello. Everyone in the station, they will learn more about constructors. In the last session, we learned what our constructors and how they're called when we create an object. So we also learned that as soon as we create a class, our default constructor is created and we can use their default constructor for initializing the object. We can create our own constructor also. And as soon as we create our own constructor and build, constructor is not visible to us anymore. Okay, so what happened is as soon as we create our class as soon as we create our class bigot, few functions for free. We will get few functions for free. So number one is defiled constructor. The second function that will get for free is called Copy Constructor. The 3rd 1 is copy assignment operator and the 4th 1 It's called our district. Er Okay. So as soon as we create a class, we will get a few functions for free. We have already started about default constructor and what it does in this video, our main focus will be on Copy Constructor. And in the next videos we will learn about these two Copy assignment operator and destructor. Okay, so let's starts today's topic, which is a copy constructor. So what is a copy? Constructor? Let us first understand. With the help of an example, let us create two objects. Student s win. And let's say the Roland Burris tan a Justin and remember is 100. So what will happen? Fatima traced Constructive will be called. Okay, now let us create another object student s too. In this case, default Constructive will be called. Okay, now our dream. Our aim is very simple. I want to copy the value off s one into s too. Okay, so our aim is very simple. Copy. The value office went into is too. So what I want is as to age should be 10 and s total number should be 100. Okay, so how can we do this? So there is very simple way we will do like this, Esther Dart certain age and we will give in Buddha's as one dart Get egx and similarly extra door troll number is s one daughter number. See if you will right as to dart Age is s one dotage. This line is wrong. Why? Because age is a private field age is a private field. So if we want to do something, if you want to do something with age, we have to use public functions certain age and get ege. Okay, Roll number is public, so it will work. Fine. Okay. So if I want to copy the value of Festen into s true, I have to write these two lanes. I have to write these two lines explicitly. Okay, so we do not need to do this work explicitly. We have a constructor for doing this work. And that constructor is called copy constructor. Okay, so what copy Constructor does is it creates the copy. It creates an object which is copy off other object, which is copy off. Other object. So this is the work off a copy constructor. So let's there's taken example. Let's create an object. First Student s one a Justin, remember is ended. Now I want to make a copy off student s one. So this in Texas Very simple student s to and we will give SNS perimeter. Okay, So what will happen? The properties off the values off s one will get cooperating. Toe s to. So in this case, Paramount priced constructive will be called which we have created in the last radios. And in this case, copy Constructive will be called Okay, which will copy the value off s one into esto. So how this land will be interpreted this land will internally look like this s one dot Sorry s too not You have a function student and input will be s when perimeter will be s one Okay, So s one is off type student s and is a perimeter off type student Now we have not created any constructor which takes one argument off type student as input. Okay, we have not made any constructive which takes one argument off type student but we are able to use it. How? Because s own As we create a class copycats repairs also created. Okay, so what will the effect of these two lines? So the effect of this line is very simple. Age will be 10 on rule number will be 100. This is s one and the effect off this line ages then rule number is 100 and this is student Okay, now one thing here is since copy constructors a constructor. It will be called on Lee at the time of the creation off the object. Okay, now let's see in court, let's make an object story in desperate A Justin really embodies 100. So copy perimeter iced constructor will be called there. Okay, We have created this man imitates constructor and let's spend something so see out Yes, one and let's go display function. So it's rendered display. Okay, so no, make another object. This object will be the copy Off s an object And let's sprint this object also student as to esto dart display. So in this lane copy construct a little bit called. And this copy constructors in bed constructor. Okay, so this pattern it dies. Construct barriers user defined. We made this constant play does not so this better my days Going stupid is not given by class V created this constructor. Okay, so user defined. Okay, so now let us in this fight. So the value off this is guarding printed parameters construct Paris called constructed three called the value of Faith for storing dishonest in and for the student also 1000 100 . The value for lumber also seem so one thing It is so one thing the north Here is there is no constructor called message for object s too because for us to copy Constructor is called and we have not made our own complete constructor were using the internal copy constructor . And in that in bed, copy constructed there is no see out message. So that's why I know See what message will appear for object as to So in this way we can use copy Constructor toe, Create copy off the object. Okay, so in this way we can use copy constructor to create copies of the object. Now here we have created objects surgically. Now let's see what have listen takes for creating objects, creating copy off objects dynamically So it does first create a object. So student s tree is new student and let's call parameters Constructor ages 20 and the number is 200. Okay, now let's Brenda stry as three arrow display. Okay, Now let us make copies off Ste So student s for as three now. Is it right? Is this index rate? No, it is wrong. Why? Because s trees a pointer and I wont values. So we have to use a de defensa Peter No student s or is the copy off s tree? Okay, now we can create our dynamic copy also. How so? Student is five is no student and star Ste. OK, we have used the offense operator. And what if we want to create the copy off Static object? So Syntex will be student at six. Is no student and static object s one. Okay, so this is how the corporate constrictive works. So a student s for is the copy off history as five is the copy off history. Okay, so we're coping the values off s tree and to s five. Similarly, the values off s one is being cooperating toe Essex. So this is all about Copy constructor. Okay, so now we know what is their default constructor And what is a copy constructor? And next radio We will learn about copy assignment, Operator. Okay. Thank you. 7. Copy Assignment Operator and Destructor: Hello, everyone. So in the last radio were discussed about copy constructor. So in this video, we will learn about copy assignment operator and destructor. Okay, so let's start with the copy assignment operator. So let's take an example. Let's create an object first. So student s one ages. Tendo, lumber is hindered. We have another object. We have another student as to ages 20 and the number is 200. So in this case, and in this case, in both the cases, paramount priced constructive will be called so paradise Constructor is being getting cold . So what is this scenario? The effect of this line is very simple ages Stone rule number is 100. This assessment and the effect of this line is also very simple. Is will be 20 and roll number will be 200 Now let's see what is over him. So our aim is very simple. What I want to do I want to copy the valley off s one into esto. Okay. I want to copy the value of fester into s too. So is will become 10 and rule number will become 100. So after creating the object, I want to copy the value off Turn into s too. So the one simple way to do this is with the help of copy Constructor. So after creating the object, can I call copy constructor? No, See, the objects are already being created. The objects are already created. So what I want is after creating the object, I am coping the values off One object in tow. Other object. So, after creating the object, can I call copy Constructor dance? There is no we cannot call Copy constructor because we know for one object constructor is called on Leavins and there to at the time of creation of the object and for s two paramilitaries. Constructor has already been called. Okay, so what we have to do? We have to copy the value explicitly. So copy Constructor Velarde Welker. We have to cooperate. A volume explicitly. So for copying the value explicitly, we have to write two lines. One for copping Dacian and therefore copping the lumber. So for copying the age age is a private feel. So what we have to do? We will use public function, get trendsetter function. So Esther Dart said age Then put will be perimeter will be a storm dart get age. And since the real number is public so we can access public, we can access public matters outside the class. So Esther Dart rule number is as an order number. Now, the point is, we do not need to read these two lanes. We do not need to write these talents explicitly because we have operator, which will do our work. And that operator is called copy assignment Operator. Night Operator is called copy assignment operator. So instead of writing these two lanes, I will write just one simple line Esto equals s one. And that's all as two equals s one. So what do the effect of this line? This line will say? Copy all the red lose off as soon into esto copy. All never lose. Office went into as to. And this equal operator is called copy assignment Operator. Okay, So what is the difference between copy constructor and copy assignment? Operator? So our differences Very simple. Copy, constructor. What it does is it creates it creates the copy. Other time off tradition of the object. Various work copy assignment operator does is Corpus Emond. Operator will be useful when Bodo objects are already created in the memory. And then we have to copy the values. Okay, So, copy Constructor, create the copy at the time of creation off the object and corpus entrant operator is used when Bordeaux objects are over, represented the memory and then you have to copy the values. Okay, so basically, they're the same book. They're the same book, but like they work differently. Okay, So copy constrictive will be called at the time of creation of the object to create copier for their object and copy assignment. Operator is useful when two objects are already present in the memory and then you have to copy the values. OK, so enough of Tory. Let's see in court how this will look like so first tell, it does create two objects so that I can use copy assignment operator. So student test one. Let's say their ages 10 and there are a number is 100 let us create another object student as to ages 20 and rule number is 200. So what we have to do is when simple ting as two equals s one. Okay, So copy assignment operator is used here. So Corp assignment operator is also given us by declasse. As soon as we create a Class Corp assignment operators also created. Okay, so what if we have our dynamic object? Then then we'll listen. Takes social industry is new, student, it just 30 and rule number is tendered, so those index will be quite similar. Start istea is s one cooperative really off has run into history and similarly cooperative Really Off s three and s to Okay, so that's all. So this is how copy Constructor books. Okay, so copy the value off s one and two s two cooperative value off s one into history and then copied the valley off Este into as to And this operator is called copy assignment operator . So there's all four. Copy assignment, Operator. We can create our own copy assignment operator also, but we will do it in the next reduce in the videos later on. Okay, so no. Now let's talk about Destructor. What is the destructor? What is the purpose of district? And without the properties were destructed so as the name suggest were destructive will do . It will be a locate the memory of the object. It the locates memory of the object delegates memory off objects. There are some properties of destructor. For example, it will have the same name s class Name? Same name as glass name Northern type and it will not take any argument. So no input argument nine put perimeters. So if you remember, these three are also the property of their default constructor. The four constructor also places all these three properties. So how can we differentiate between Destructor and the fourth constructor? So over the real room we will use a special symbol called Taylor. Okay, so we will use the special symbolic Ortega. So that's in text. The structure for destructor is very similar, but they're constructed student nine foot perimeter and northern paper. So this is the structure, Rafa, this is the structural for destructed. Okay. And the structure for default constructively already know Northern type nine foot argument ? Nothing. Okay, so this is the structural for default constructor. So destructor is automating decorated as we create a class. Okay, so just like the constructor, a destructor is also called once in the lifetime Often object so vendor destructive will be called district level because when the scope of the object finish when scope of object finish, Then destructive will be called. And when the constructors called when we create object, Mr Constructors called When we create object Destructor is called when the school off the object finish ok District is also called once in the lifetime and construct as well so called once in the lifetime of an object. So just like constructor, we can create our own destructor. But we do not pass any argument. Okay? We cannot pass any argument to the district. Er so constructors can be many. They can be many constructor in the program in a class. But destructive will only be one. There will be only one destructor in a class. Okay? What happen is if you will create our own constructor than the Ford Constructor goes away. If we will get our one constructor default, constructor goes away Similarly, if you will create our destructor then in bed Constructor goes away and our destructive will be coiled. Okay, so let's see in court suppression Symbol district. The name is same as the name of the class and that's all. Let's bring something here. So see out Destructor Gold. Okay, so no. Since we every time our own destructor. So our destructive will be called Okay, however destructive will be called inbuilt. Destructor is not available to us anymore. Our district er will be called because we created our own destructor and then destructor will not be called. Okay, so vendor destructive will be called when the score of the object finish. So we can see here. We have three objects, two objects Esther take and one object is dynamic. So at this line, line number 15 the scope of the object finish. So as soon as we reach line number 15 destructive will be coiled. Okay, destructive will be called as soon as we'd each line number 15. Okay, so what should be on output? So at this line, construct the number three called which is a parameter ized constructor again, parameters constructive will be called custom poetry called again constipated called Now, when we reach this lane, all put will be destructor called again Destructor cold and again district accord by two times because we have three objects. So three objects. So to time Distractible recoil for the locating the memory of the object. Okay, so this is our expected output. And now let us in this file. So first we have to run this file because we did changes to this file and now we will run this file. So Constructed recalled constructed three cold So this time constructed Stays coiled for this one. Step two take oil for us to constructed. Recoiled forestry Now disturb Official destructor is being getting called on your two times The structure is called only two times but we have three objects So why Destructor is called two times Why not two times. So let us try to understand why two times and why not three? So what is the effect of this lane? Ages been Rule number is 100 on This is our student Test one and let's there. This is 500 What is the effect of this lane? Age will be 20 Rule number is 200 student too. And let's air bases 600 What is the effect of the slain? So we are creating the object dynamically. So we have a point artistry and then in the heat memory. We have ages 30 and rule number is 200. Okay, lets say their bases 700. Okay. And then we are doing some stuff. Okay, So at this land, what will happen? Constructor should be called. So what constructive really do It will destroy the memory. It was. They locate the object. So on Lee, these part will be diluted on distracting memory. Wilbur dilated Only starting objects will be diluted. Okay, so this is an artist rating object. So constructor will not be coiled for this. Sorry. Destructive will not be called for. This destructive will only destroy this object and the subject. And since this is not object s trees not object, destructive for history will not be called. Okay, so our destructive will destroy only these two objects Destructive will be coiled for these two and not for history. Because history simple appoint a variable. It is not an object. So what we have to do? It is our responsibility. We have to delete this class we have toward earlier this object. Okay? It is our responsibility for delayed the subject. Now how can we delayed this object? So, in the dynamic memory allocation, we illustrated how to delete dynamic memory using a giver called believed. So we were right. Dilute s tree Verbal. It s table do. It will come here. And as soon as we will come here, Destructor for this object will be called Destructor for history will be called and this memory will get diluted. This memory will get diluted. Okay, So always remember always remember, if days are dynamic memory allocation, then dynamic memory location has to be the litter by ourselves. Okay? They're not automatically deleted on least Arctic memory. Static objects. They are deleted automatically for dynamic memory. So the located we have to use the keyboard. Delete. Now that does destroy object s tree. So delete history. Now the destructive will be coiled. Okay. See, Mr Place being getting called three times. Okay, So this is all about Destructor. Thank you. 8. Play with Constructors: Hello, everyone. In the last few videos we learned about constructor and decision. I will try a few more interesting examples. So this is our glass student. So the student class has one private property age. And then we have our destructor, our default constructor. And then we have two parameters. Ized constructor. The first turn takes rule number is input. And the second parameters constructor, take agent roll number is input. And then we have a public field, a public property rule number. And then ah, public function display Got age function and set age function. Okay, so now that does create some objects. Student destined? No. Which construct rate will call it required. Default Constructor. So constructor one called. So they're defiled. Construct Berries, construct Kevin. Then parameters constructor to which takes on the role numbers in port is constructed toe and the constructive which takes a general number, is constructed three. Okay, so in this case, custom Kevin will be coiled student toe and let us give rule number is input now which construct rate will call it will call in constructor toe So constructor to guarded story entry Now, this time I will give a general number. So 10 and 100 no constructed tea will be called here constricted three card student four and as three years and put strolling three years input now, which construct double recoiled. So copy construct level because there copy Constructor called. Not this copy. Cancer place and build. Copy constructor. Okay, Now what if I do story and one equals Student do now which constructive will be called here . So no constructively record Their boat s one and s two are already created in the memory. So copy assignment operator will be called copy assignment Operator. Okay. Copy assignment Operator called or be constructive Lord recorder. Why? Because both external destro are already created. They already exist in the memory. Now let's take one more example Student. It's five equals s tree now which constructed will be called here. Got bigger, Stricter. So copy constructor coil Here. Now let's see. See, what is the meaning of this line? We are creating a new object and then we're coping the values off as three and two s five so we can break this line into two lines. First we are creating an object and then we are hoping the really off student. Three objecting to strand five. Okay, so in this lane, defied, constructively recoiled. And at this line copy assignment operated with the called. Okay, Copy assignment operator will be called Mark if I see it. This lane. If I see this line, then copy Constructor is being called. Why? Because what company level do? So these are two lines. Okay, so work come by level. Lou would come by level. Do it will optimize. It will convert these two lines into one single line. Come by level optimize so optimize internally come by level and different compiler will interpret this line into one single line, which is student s faith s tree. Okay, so compiler will interpret these two lanes in this fashion. So if you're right student as FIFA Quest s tree s tree, this is same as student. It's five record Astri. Okay, so that's why copy constructor is called Copy Constrict Base coiled here. Okay, so this was a special case student that's five equals history. This is the special gifts, and you must remember it. Okay, so this time corporate respectable because there and not cope Assignment operator. Okay. Thank you. 9. Fraction class: Hello, everyone. So, in the last figure deals we learned over days object oriented programming. But I it's different concept. How to create objects. What are construct Aranda? How to use them. So we have learned a lot of things in object oriented programming. So now let us create a class with help off everything that we have learned till now to gain confidence and to make things more clear. Okay, so let us create a fraction class. So in Matt in minutes, the example of affection is like five by seven, 5 15 you miniter and 70 disseminated. Certainly present these type off numbers And to perform operations on these type of numbers , we want to create a fraction class. Okay, So infection class, we will have to properties numerator and denominator. These two will be the properties off our fraction class, and both the properties will be private. Okay. What? The properties will be private. So five is the numerator and seventies. The denominator. Okay, so let's see in cold. So here I'm grating on live in class if you want. What you can do is you can clear the class fractions or CPP. Sorry. You can create a file fraction or CPP and another file fraction used or tpp. But I am creating only one file. Okay, so it's totally our choice. So gas fiction? No, we want to properties bought the property. Italy Private So inter numerator and denominated. Now what I want to do is now What I want to do is whenever we create object off this class whenever create object off fraction class, numerator and denominator should not contain garbage values. Okay, numerator and denominator should not contain car visual loose. So how can we ensure that? How can we enforce several user to give the values off numerator and denominator? So the idea is very simple. We will we will make a perimeter ize constructor And as soon as we make ah parameters, constructor default construct is not visible to us annual. So in this way we can for several user to give the values off numerator and denominator. Okay, so let's create a pandemic based function. It will take numerator and denominator eyes input And then we will cooperate the value off numerator and denominator into our properties so enumerated it quotes numerator and they nominated. It causes denominator. So in this fashion. We will force other user to give the values off numerator and denominator. Hence, if the user wants to create our objective friction class, numerator and denominator will never contain garbage values. Okay, so are these two lines correct? Will this two lanes work? No. The stolen artwork and rival large work because the property name is a mess. Function Name? The property name is same s perimeter name. So we have to use discovered using this is mandatory here. Okay, so now we re create the object of defection class. So we will create object in this flesh infraction. Let's call it definitely so the new military spin and their dormitories. Five. So numerator will contain 10 they nominated. We contained toe. And this is our affection F one. Okay, Now let us create a brain function. So what the sprint function will do? It will print our affection in this manner, then fired. Slash Do Okay. So virtually Jessica Nature of print function. What does it return? Type written and I will be void because we are not returning anything, friend. And then some court, okay. And how we will call this function. We'll call this function with the help of an object. So f one dot print the valley off F one f one will be stored in the this giver of the brain function. With the help off this, we can access the properties off F one. Okay, so private function will be public or private. It'll republic because at the right subject cannot call it so I returned Type is weight because we're not returning anything. Nine. Put argument the object which will call the print function. The object will be stored in this. So see out this ad enumerated, then forward slash. And this little did not mean it it. Okay, so using this is optional here if he will not write this. Okay, so using this is optional here. We can also remove it here. So whenever the object will call the print function f one dot print, the value of happen will be stored in this. And with the help off this, we can access the properties off the object. Okay. Now it does create one more function. We want to create a function ad. We want to create a functionary. Let's say we have to affection. You will get a functionary. Let's say we have to Fraction F one. The value of a friend lets it stand by to an infection after which is like 15 by four. Okay, so what is the signature of add function? So add F one f two. It will take to fraction as input. Is this right or wrong? It is wrong. Why? Because to call a function, we need an object. Okay, To call a function, we need an object so everyone will call our objective called dysfunction. So what word Dravida input parameter divert a little argument for our function. Since F one calls the air that this giver of the air function will store F one. And now we won't have to several pass after s input. So it will take only one argument and not to argument. Okay, fine art to argument because everyone is stored in this giver of the air function and we will pass F two and similarly air can perform its operation. Okay, So what is our expectation? What is our dream? Our dream is we want to abrade the result off F one plus F two and with one we Willard. These two friction a friend plus after and will store the result in F one, We will update F one and after will remain unchanged and we do not want to create any new fraction so the return type will be void. We do not want to create any new fraction that origin type will be void and we want to update F one and after will remain unchanged now. How do we had two factions? What is their procedure for adding two factions? So the procedure is very simple. Let's say that two fractions are then my do, and the second infection is 15 by food. Then by 2115 by four. So first of all, it will take calcium and say miss four. But now, for simplicity, let's make it eight for simplicity. Let's make it it. Okay, so here it is not clearly visible. So let's say the two factions are a friend of to so f one is then my do and after is 15 by four. So how can we had two factions? So, first of all, we have to take the l some of their denominator, so they'll say miss four. But for simplicity, let's make a date. So what will happen to the new militar? So this 10 will guard multiplier by four. How for? Because it by do is for similarly this 15 will get multiplied by two. And from there to came, it is simply it by four is too so enter too. So 40 plus 30 Buy it. So our dessert should be 70 by eight. Okay, so for now, let's call it X. And let's call it way. Okay, So what is X excess? Simply the l C M. Divided by the denominator. And where this way, why is calcium divided by Dermot drove after And where does else him? Elsom is denominator off F one bless Saudi money to play dear made rough after the murder of F one multiply denominator off after. Okay, so let's in court. So we want to create our function, our function with the public or private. It will be public because it will call it from the mean what it will take. It will take a fraction as input infection after, let's name it after. So first of all, we have to calculate calcium so we'll see em is very simple. Dana Meddoff, F one multiply demographic F two So after dark denominator. So using this is optional here by optional because who will call herd An object will call it F one will call Ed and f one will be stored in this. So this simply means f one here. So using this is optional here, you can also remove this. Okay, so this dominator and visit Li means this error denominator. Okay, now they discovered the value of X and way So X is very simple Calcium divided by denominator off F one So denominator you can write this entertainment also and similarly why is also very simple? Vai is I'll see him divided by after dark denominator. Okay, so using this is optional here and here it is mandated to use this. So using this is optionally okay. No, What was our him? So first of all, let's calculate nominate also so in the numerator is ex multi play Numeroff F one So you can simply rent numerator or you can write this I don't America place via multiply after dark numerator normally draft after? No, as we discussed store that desert in F one stored result in F one after will remain unchanged. So this Adam numerator is and, um, this editor denominator dinner draw off F one is Elsie. Um okay, so optional using this is optional because of this implicit. Okay, so what will happen? So little defections are f one is then vedo and afterwards 15 by four. So numerator condensed in there are only two contains two This is everyone Numeraries 15 being address for and this is have to So what else? Several do? What was the effect off line number 18 So they murder multiply after dark dormitory So too multiply for it. So l c m is it now? What of the value of x X is so x is lt um which is it? The Wedderburn Dermagraft F one. So it by do which is food? What? This way? Calcium divided by denominated off after which is now what will be the numerator? So numerator is X which is four multiple in a minute off F one or we can say this era eliminator 10 plus where the really off way which is to multiply 15. So this comes out to be 70 and then we will store the result in F one. So after story, in years old enough When this afternoon editor is And, um let's say the services 700. So this contains their function. This give all of their function contains 700. So this ad in the military's and, um so it will become 70 and this will become the center dormitories Elsom So wholesome is it so this will become eight. So finally, for F one, the new militaries 70 and Ordina militaries eight So f one is 70 by eight and after Louis 15 by four. So this was our dream after remains unchanged after remains and changed and everyone guard abated So f one became f one Bless after Okay, now idly now widely f minus 70 by it But this is not simplified. After a simplifying, we will divided by two so it will become certified by four. So this is the simplified manner we should store reserved in this manner. This is simplified way Okay, now how to simplify affection So it is very easy to simplify affection But you all know to do is so what is that we deserve are reserved is very simple Left one begin 70 by eight now I want to simplify distraction So our is ensured bitter to five by four. So it is very easy to simplify affection. But we all know to do is find Adji city of these totems. The city means highest common divisor to find a city, you said they will come out to be too. And after finding Lady City divide, numerator and divide dominated so numerator will become new military derided Reggie City and Denominator will become Denham. Enter Baiji City now. How to conclude a city, for example. You want to call it Reggie City of two numbers four and 20. So what can with a maximally obesity? So the maximum really off the silicon before? Okay, Maximally of the silicon before yesterday is the highest common divisor, a number which will divide both the number four and 20. We have to find a number. We have to find the highest number, which divides both the number four and 20. So the highest rate of obesity can be for Okay, So what we will do will start dividing from one. Then we will divide from two and so on till the minimum off. Two numbers e and B for example, and where the two numbers who just they want to find. So I will start from one. Tell me now for envy and I will divide. I will divide. I will try to divide both number A and B by these numbers, and the Mexico of this number will be our D city. OK, so let's say in court. So let's clear the function. Simplify. So we have a function wide Simplify. So what it will take It will not take any argument. Why? Because how will call this function and object will call dysfunction object dot simplify So the object will be stored in this giver and with the help of discovered, we can access it properties. So initially, let's say gee, city is one and the maximum value of the city can be so J city make similar ethnicity can be minimum off numerator and denominator. So this had a numerator, this adult denominator. So using this is optional here optional by optionally because implicitly Dana matter means this era denominator so optional. Okay, so the object that we call this function that object we restored in this Gifford and with the help of this giver we will be able to access the properties so we will start dividing from when and we will go. Bill J J still maxims you should devalue so try to divide numerator and denominator Baiji. So if new miniter more I a critical zero and denominated more I equals equals zero. That means I is a common factor. Often omitted Indian immigrants So we will have a great day City So the city is I Okay Now , after calculating Lady City, we have to simplify defection so simplify so for simplifying But you can do we will abate numerator and denominator So new Meritor is new miniter divided by dcd and similarly dominator is the interrogator divided by the city Okay now very call this function Simplify So after there are a function our result has been abated The result has been stored in F one So after starting the result NF when we will call the simplify function so simplify Now this simplify function will simplify f one Now see here how we used to call a function how we used to call a function used to call a function something like this Object dart function name object named art function name. Okay, but here I simply here, simply right on the function name. So how it will work. Basically basically what I were doing here F one dort ed after. So if one is stored in this, give erred off the air function. So we are in the air function. So in their function, simplify implicitly means this aero simplify. Okay, implicitly simplify This line simply means this era simplify. And this contains F one. Okay, this contents f one so everyone will be stored in the F one will be stored in this giver of the simply where function. So here, this gave earth will store F one Okay, so similarly, it is optional to write this ad eliminator because implicitly it means this also it missed this only. Okay, now let us try to create an object and let's see where the rubber cord is working or not. So infection s Lynn. Let's see. The numerator is what we decided. 10 and doing so. New military is to raise so in humanities. 10 denim address too. And I'd say we have one more fiction have to. So what was the name? Attended him into 15 and food? No, like that's cool air function. F one dark aired and we will pass F two now after the addition. Let's spend the value off FNN after. So a friend or a friend and after dark print. Okay, it's from this way. So Anu Mittal was something wrong here. So what did I do wrong? No matter. Does not name or type you monitor does not name a type. Oh, silly mistake. Okay, let's give and Lanier so off in the brain statement. After bringing the new maternity reminder, let us give Elaine. See. So the new minute so that if one is 35 by four, everyone is certified before and after is 15 by four. So if one was initially 70 by eight But we called the simply by function. So it became 35 by four. And after remains unchanged, it was 15 by four. And after the addition function, it is 15 by four only. Okay, sorry. Record is looking now. I want Oh, just for extra information. We also have a function we also over in bed function to call Grady City. So when brain function were calculating, the city is very simple. So let's committed out. So when Bill function in bed function for the city. So this is are in discord in the school GCT and give the two values A and B, for example e and b other two numbers who just really want to find So how can we use this? So end A Let's say NC civil contain the G city off two numbers. So the city off two numbers a and be Okay, So this is evident brain function and that's going to scold you city. It is an gilbert function. So we can definitely use this or we can use it in this faction. Or you can find recon Convergence City indecision. Okay, it is our choice. Okay, So that's all for this video. Thank you. 10. Fraction class continuation : However, even so, in the last session, we create reflection class. And now we will discuss some important concepts that were not covered in the last session. Okay, so first, let us analyze this fraction class. So in distraction class, we have to private properties, numerator and denominator. Then we have a paramount driest constructor, a brain function and our function. Okay. And then we created simply fire function at the last. Okay, so this is all about the fraction class. Okay, now, let's see. Now let us analyze the function. Heard what is happening in the air function. So we have two fractions. So the numerator and denominator for for instruction Waas pannitto This is affection F one and numerator and denominator for affection towards 15 and food. And this was our affection toe. So how were calling this ad function? F one dart heard, and we pass after west perimeter. Okay, So what is happening here is we are making a copy off f toe here. Okay, so ah, copies being generated. So what is happening here is we can we can write this Linus fraction after. Is it questo fraction F two from the mean Okay, so this pattern it reflection have toe this pyramid affection after. Is it close to the fraction from the mill? So what is happening here is we are creating. We're creating a new object and all the values are being getting copied. Okay, So what is happening here is copycats took place, being getting called copy, Construct various cold here. Okay, so at line number 17 at line number 17 Copy Constructor is being getting called. So copy Constructor is creating an object and then it copies the value from the fraction which is present in mean. Okay, so what? Our aim is So our game is Our aim is very simple. We want to avoid a copy. They don't want to copy. Okay, We want to avoid this copy. So why do we want to avoid this copy? Because if you look in the if you look inside the air function, we are only accessing the properties of friction after we are only using the properties affection f toe. So where to copy? If we will copy than there is time and memory waste. Because first our object will be created than all the values will be copied. Okay, But we only need to access its properties, so there is no need to copy. So ultimately our aim is we have to avoid this copy Now how can we afford this copies? The question. So how can we avoid this copy? So we all alone? We have started about references variable and passed by reference in function. Okay, so what we will do? We will pass by reference to avoid copy. So let's take an example. So when we right and dies five and energy is I What happened at this lane? This is the scenario and had this line A memory block will be creator J and the value will be copied. But we want a new block. Should not be there. So we will use reference Variable. So what will the effect off this line? The effect of this lightness is very simple. Okay, Okay. They both points to the same memory block. I nkp belongs to the same memory block. So if I will do K plus plus than this value will become six. Okay, so if you do see out K or if you see out, I our poetry basics order will be six. Both I n G points this memory block. Okay, I can change. I can read and write data. They can also read and write data so we will use reference variable. So the scenario will look something like this fraction reference variable is main dot after . Okay, so in this way we will be able to avoid copy Okay, so let's see So what we have to do? We will avoid cop using the reference variable Now there is still a problem. What is the problem? So suppose if I do something like this after dart numerator is minus one I am changing the values off after I'm changing the numerator property off have to. So my aim is Miami's To avoid this toward this no one can change the values off numerator No one can change the values off after So how can we do this? So how can we achieve our goal? So it's very simply what we will do So when we right and I is five and caravans very bulky is I? What happen is the society and this is K I can I can read and write data can also read and write data but there should be a V if I do OK plus plus then era should be there. I want cake and only read data they should not be able to write. Data can only read data so far to do so. We have a constant reference Variable. Where do we look? The same. Texas looks something like this. And constant reference Variable K is I so Geza reference Variable toe wearing teacher constant que sera France variable twenties A constant. So K is a constant reference. So if you will use this, then what will happen? So this is five. I n ki both points here. I can read and write data, but they can only read it on K cannot write data. Okay, Okay, okay. Cannot write data. So we knew something like this in our program. So what do we do? We will create a constant reference. So constant reference. Okay, So whenever we are working on a project, we should keep all these things in our mind. Now, get this more small things matters. Okay, So you should always think that whether I should pass a constant reference so simply passed by value. Okay, so these things matters. These things really matters a lot. Okay, Now let's just cleared one more function. Ah, function called multiply. Just like their function, we are creating one more function which is called Multiply. So multiply will do so multiply function will multiply two fractions and how we will call it f one dart multiply after. Okay, we will pass one argument. So our aim is same as the M which was for our function the real multiply F one and after we will multiply f enough to end store that result in F one. Okay, after will remain unchanged, we will store the result in F one. So how to multiply Two factions support Stephanie's 10 by two and we have another faction after which is 15 by four. So much pain numerator with the numerator and multiplayer denominator with denominator. So 1 50 by eight and then we will call simplify function. Then we will call simply five function. Okay, simple, easy. Now let's right the court so the return type will be void. Let's hear. The name of the function is multiply. It will take a fraction as input. We will take a constant reference because we do not want a copy constructor be called here because there is no need to copy. Okay, there's no need to cope is a way to call copy constructor and waste our time and memory. So we have to multiply a new motor with the new miniter. So new minute off F one is new Minute off F one my reply Numerous drop f toe So I have to start numerator. Okay, so using this is optional here. This is optional. So we have to motivate denominator with diameters are denominated Ralph F one It's Dermagraft f one multiply their monograph have to and then after multiplication ist and we have to call simplify function. Okay, after my application, we have to do you have to call simplify function Now after the addition, let's go back to play for native to so a friend Art multi play. We have to pass afterwards argument And now let us spend the value of definitive to so f one dot print have one dart sprint and similarly lead sprint after so after dark sprint. Okay, so that's all. So these are the values of a friend. I have to after the addition and these are the values off, offended after off the multiplication So we can see here the value of have two remains and changed. And when these two are multiplied, we will get this result 5 25 by 16. Okay, so go to the school and try to understand each and every line of the cold, so on, That's all from my side. Thank you. 11. Complex Number Class: Hello, everyone. So I hope fraction classes no clear to you all. If it is not clear, then please do it again. Try to clear deflection class on your own. In this session, I will discuss the problem that you guys will implement. I am just giving you a different production on how to implement it. In the last session, we implemented fraction class. So now you guys have to implement complex number class. So in Meds complex Steinmetz, there are complex numbers. So complex number is like we have a real part, and we have imaginary part rial Parton. Imaginary part. This is called iota. Some people represented with G also but prefer this I Okay, so example is three place for iota. Okay, so this is a complex number. So complex. Numerous true parts. Real Parton. Imaginary part. So how we will implement this class, how we will implement complex number class. So first awful. We will have to private properties. Two private data members, Really and imaginative. So these will be to private their members to private properties. Okay, So they both really private. Now, let's see. So let's say this landline number 10. So what is this? It is a constructor. So this is a perimeter ize constructor. And this paramilitaries constructor is taking two values First, the real part and second is the imaginary part. Okay, So for example, how we will create object so complex number Name of the class See when and let's see the real part Astri and the imaginary part This five So what will happen? The paramilitaries constructor really part will be set to three real part will become three and the imaginary part will become Fife. Okay tell part will become three major part will become five So I am using parameters constructor here. So why parameters, constructor? Because if I use, everyone should create object off my class He has to give the value off Rheal part and they make any part. So my realtor measuring part will never contain garbage value. Okay, they will never contain garbage value. After that I will take a choice as input from the user. So if the choice is one I'm calling a function see Even dart plus C two So bless is a function president function that you guys will implement. So what passed function will do it related to two complex numbers. So see you too is a perimeter Soto's argument off type complex number. Okay, so what this plot function will do, It will add two complex numbers and put the result in seven. So add two complex numbers even plus u two and put the result in seven. Just like we did in the fraction class, we will air too complex number. And for the result in convex number seven. Okay, so you two will remain and changed. Sciutto remains unchanged. Okay, so what is that? Returned? But with the return type of the plus function, you don't I will be void. We are not returning anything. Okay, so how do I took on blacks number? So suppose seven is three plus four iota and see you do is five plus when I order So what will be seven plus u two seven? Plus it will be really part plus real part. So it place five iota. Okay, so this re our new really off seven. So this will become seven and C two will remain and changed. Sciutto remains and changed. So this is how we air the complex number. So you have to complete this plus function. You have to write this plus function and then after doing plus after in place operation. But we are doing we are printing. We are printing. So how we will print will print real part first, then plus then iota and then imaginary part. Okay, so this is how we Brent a complex number. So what if the choice is to if the choice is to have a function called c even might apply. So Stephen Dartmouth to play Sciutto. So this multiply is a function that you guys have to implement. So this multiply function doesn't have any return type. Return type is void and it will take object off type complex number. Okay, so this so this multiply function, which will do it will take to complex number seven answer to multiplied them and put the resilience even. Okay, So Mark deployed two complex numbers evidence you, too, And put there's evidence, even suitable women and changed. Okay, So do you guys know how to make reply to complex number? So I'm just giving you off beef idea. So let's say see, when is three plus four iota and si two is five plus one iota So Stephen multiplies you too . The first awful riel. Part multiple aerial part. So three into five with a negative sign by never designed because I wrote a square is minus one and then imagine apartment to play imaginary part of so four into one. So this will be you, it real part Now it's trying for imaginary part. So iota so measuring part will be three into one plus four into five. OK, so what is the formula? Formula is very simple. Real part off Stephen Riel, Part seven Multiply real part C two negative sign imaginary part See, Even multiply imaginary part C too. So this will be your really And they made any part will be real part off. See even Mike to play imaginary part off Sciutto Bless Sane Real part off. See, too Mike to play imaginary part off. See even. Okay, So this is the formula for mark tipping too Complex number. I hope you guys already know this formula, but in case it would run, though I just gave you the formula. So what we're doing here is after the multiplication, we are printing seven Stephen dot print. So print is also a function. Prentice also function so Prentice, nor taking any argument and return type will be void. Okay, So best of luck, Grace, I hope you will be able to implement it very easily. Okay. Thank you. 12. Shallow and Deep Copy: Hello everyone. Welcome to this news station and this session we will learn a few more important concepts off hoops if you notice In the last session we never used student name anywhere, student name with an important property in that should be included. So we should have to random property. But we did not include it anywhere Rival yard included because there is a reason behind it . So now let's see how we will work on name. Okay, so it does create a class student. So that does create a glass student. Now, this time I will have to private properties a general number. So age will be in teacher Israel being teacher and is a private property. Now the name will be a string. So for storing a string, we will use a character very so care name and let's say the sizes 100. Okay, so we should not do this. Why? Because now we're started dynamic allocation. So now we know how to create an aerodynamically So we should not create arrest critically. So creating that aerodynamically syntax is very simple. Gaston name is new. Cat 100. Okay, so the problem here is there's a problem here And the problem here is we do not know the size. The student name. If it is more than under, then we will be drab. If it is less than 100 then a lot off memory will be wasted. Okay, so according to the requirement, we will decide the size of the store in name. So for now, let's make it a corrector pointer. Okay, so let's make it a character point only. And according to the requirement, we will look good sides. So now let's create a constructor. So they're gonna strip. There will take two inputs, age and rule number. We're constructing a bad image. Tries constructor so and age and second will be name. Name. Okay, So this average we have to use this hair because we have to differentiate between the perimeter and the property perimeter and the property agent. So this era wages age and similarly this Everyone name its name. Okay, so what? Constructive is ready now Let us create our display function so that we can print so display so display function. Let us first Brenda value off name first We had bringing the name of the student and then we will bring the age of the student. Okay, so now it does create objects. So student s one. So is the statement right or wrong? So this is wrong. Goodbye. Because as soon as we created a perimeter ize constructor, then build constructor and waved default. Constructor is not visible to us anymore. So this line, But it will do it. We tried to call inbuilt defiled constructor. And that constructor is not as well. So this line with through edit. Okay, so what we have to do? Okay, so first let us create I name Ah, string name. So can name. Let's say the name is Let's the name is a B C d. And now let us create a student. So student s one. We have to call parameters Constructor, Let's say the ages 20 and the name is name. Okay, so now let us call display function. So it's one dart display. Okay, now that does create. Okay, so now let us change the value off name. So let us make the name ABC. So now the name is ABC. Now we will create another object. So a student, Let's name it as to so the ages 30 and the name is name. Okay, so now let us call display function. Okay, So if we will win this file, what will be our output? So let's see. So forced to rent Usman name is baby sitting and they ages 24. Student is to name is ABC and the ages 30. Okay, so this was our expected output. So there's nothing new here now. What if after printing s too What if after bending is true, I am again printing the value fest one. So what will happen? Aspen dart display function. Sorry, but should be a B C D and 20. Now let's see what we are Output See, there's something wrong here. The airport should be the name should be a BCG but the output is coming out to be a B c. Okay, so visor. So let us try to understand what is going here. Let us analyze what we have done. Okay, So what is the effect of the slain? What it will do? It will create a B C d. And then and let's say there goes off the 0 10 nexus 700. Okay, so at this land, what will happen as friend art student name is 20 and 30 ages 20 and name will be 700. Your long. How correct there is our past in fact, however is passed. We will pass diagnosis of those root index. So 700 will go from here and that this language will happen. So age is 20 and name is 700. Okay, so this is the scenario head now what will s will contain. So for this one age will become 20. And the name which is a character pointed stores 700. Okay, so this is the scenario s when so basically what is happening here is so the name is pointing the words this name. Okay, so the name off s one. The character point there is pointing towards this name. Okay, Now, at this lane, as soon or display what it will do, it will print, name and age, so for name. But it will do. It will go to under 700. So we will reach at about 700 then we will print the entire content of the area, which is a B. C. D. So haters out our put south put is a B c D. and they just 20. Okay, so now what we do here is we change the third index and now it becomes E. So ABC e It is now a B c. Okay. And here how we will call, We will call as to dart student. So the ages 30 and the address is 700. Similarly, agent name will become Don t and set 20. Sorry, it will retarded 30 and 700. And finally as two will look something like this Ages 30 and as to name also contains that dressed 700. Okay, It also contains there dressed 700. And this is our s too, so as to is also pointing towards decide only then we will print the value office to so for printing the name we will go toward us number 700 print its content to the content is ABC and the Ages 30. Now again, we are printing s when as under display. So for a sonar display, we will teach s one for printing the name. What you will do. We will go toward a 700 prints the content now at the address ever rendered. We have ABC so ABC. Evil get printed and the age will be 20. So that's how ABC is coming out to be here, Which is wrong. Ideally, it should be a B C D. Okay, So what is happening here is both the objects are pointing towards the same area. If we do change in one object, it will reflect in the other object also. Okay, So what we should do? We should copy the entire area there, then copping the address only. Okay, here we are only coping that breast. Seven dirt is being getting copied. I delivered. We should do is we should copied and Terreri. Okay, so this copy this cop is called shallow. Copy. So what is the meaning of Sherlock? Official Ochopee means copy only the address. So currently we are doing shell a copy. Okay, So when every part Serie. So rather than copying the entire area, we copy their dose of the root index of dairy. So if you copy their dress, if we copy the address or ferry, then it is called shell a copy. Okay, so are now. Let's see how to fix this problem. See, at this line this at a ages age Okay, so this line is absolutely correct. Why? It is correct, because age is an integer variable. So the whole value is being getting copied. But in this case, we are only copying the address. Okay, so arrays somewhere else. And we have only copied the address off the zero to index of dietary. So this is called shallow. Copy. This is Shell a copy. I had to leave the short award. Shall a copy shall look upon me in Skopje on Leedy address of of the copy only there does of the area. So I delivered pressure Do We should create a new eri and then copied Ian Tyree. Okay. We should create a new era and then copied the entire content of dairy. So that is called deep. Copy the share. Look up is copy Onley Address off zero tendex off the area and deep copy is copied. Ian Terreri. Not only their dress. We should copy the entire area. Now let's see how we will do this. So letters first off will create a new area so that we can copied Ian Terry servo creating the new areas in Texas like similar to this Ah, new cat but it will take It will take the size of the every size of the this name. So for calculating the length we have when bill function str alien we will pass it name it will give me the naked will Give me the size for example. The name is a B C D. So sting glint str alien will give me for a B C. D s Carolyn will give before so I have to do plus one here by Pleasant because we have to also copy the null corrector. So for copping the null corrector I am doing place from here. Okay, so now we have created a new Eri. Now, after creating the new Eri, we just have to copy the content. So for copying the content we ever in build function string copy. So first we have to give their destination and then we have to give the source so the source's name copy so copied this name into this name copied the content Okay, so content will get copied now will also get copied. Okay, along with content, we will also coop eternal and Vitus plus one here because we need one space. We need one block for copping that also. Okay, now what will happen in this scenario? So the name dedicated in the mean that was containing they're just 700 the content was initially ABC the Anil. Then we will call the function we will call constructor. So for calling the constructors and text will be like as one dot student. First we will pass the age and then we will pass the name so name will be 700 So the bad image of age will contain 20 And the perimeter name will contain 700. Okay, so at this lane, what we are doing we are creating a new era. So this name, this aero name, what it will do it will create a new Eri. And what with the size of the size of that is five by five Because every city s Carolyn will give me for and no So this is four plus one So we get a new era. Let's say that most of those root index is 800 and then we what we are doing we are cropping the content. So ABC the Anil Okay, not this time this era name this error name convince you tendered. Okay, This I don't name Constant 800. So in the next step, when we change the value off name ABC when the milieu off name became ABC. And then if we again print the value off s one so there's one name contains that does 800. So it will print from here a different from here, so but so our people be right. Our put will come out to be right. ABC the only. Okay, so this is called deep Copy. So what is the procedure for Deep copy? The copy sees make a new era, which is seem as the size of the this name and then copied the content. Okay, make January make a new era and then copied the content. So in this way, we will solve our problem off shallow copy. Now, let's see. Okay, so where does compile this file? Okay, so this arrow name is sting gland. So for using the functions to England, we have to include I had a file called See Sting. Okay. So we can see here is now without putting a BCG only. Okay, so this is called shell Akopian deep copy. So I hope you guys understand this. Okay. Thank you. 13. Our Own Copy Constructor: Hello, everyone. So in this video we will create our own copy constructor. So before writing of her own copy constructor letters Analyze again. How inbred! Copy Constructor works. Okay, so let us commend out the scored. Okay? So let us make a copy first. So we have a student s two and s stories Copy. Office phone. So at this land copy constructor will be called. Okay, so coffee construct a cold. Okay, so now let us change the name off s too. So let us change it. Zero to index two x. Okay, So the name property is a private property. So to excess name, let us make name is public. Okay, we can also use good answer the function. But for simplicity, I made an invariable a public field. Okay, so after changing the name for as two story intends to now let that sprint s one and s two . So as friend art display function and similarly extra dart display. Okay, So now wonder doesn't this file Okay, so let's send this file so as soon or display. Okay, So compilation edited, See, both as Ernesto. Both the names are ex BCG, which is wrong. Ok, So the story and one name also were changed if I changed the name of the student toe. So let us try to analyze what is happening here. Ideally, the name for student Essential re every city. But it is getting changed. Toe XB city. Okay, so that destroyed during this turn away Why it is happening. So let's say this name contains that just seven entered on. We have a, B, C, D and e. So their breasts off is 700. Okay, Now, when we call parameters constructor, what will happen So age will become 20 And since we have made deep copy so the name will contain address you tendered. So this is our s one. And it turned register address off a B C d and then the So we make January because in the copy we make a new area and then this name will contain their dress. 800. So this is the content here. Ok, we cooperate This content now What will happen at this lane copy constructively were called so hard. Copy constructor will do. We've been cleared. A new object with the name is to sew. Age will get copied so age will become 20 and the name will also get copied so name will contain 800. So what is happening here is the name officer is pointing towards this memory location and the name of Festo is also pointing towards December location. So basically what is happening? Areas Copy constructor, mix shallow. Copy. Okay, that's a low copy is being made shallow Copy is created by in built copy constructor. So always remember our inbred cop because our in built copy constructor always makes shell a copy. Okay, so at this landline number 30. But we are trying to do we are changing the 0 10 next to X so go to 800 memory location and then change does wrote in next two X. So then we are printing and asserted or display an extra door display so has turned. Our display will print this one so XB City and similarly extra door display will go to address 800 we will print. So that's why XB City Okay, so that's why explicit in explicit e r printer for s one and s two. Okay, because our inbred copy concert circulated shell a copy. So whenever we have dynamic areas. Our data member as our property. So we should always create our own copy Constructor Toe award shell a copy. So when we will create our own copy constructively with blue deep copy. Okay, so it is important hair. It is a It is very important here for us to create our own copy constructor because we do not want shell a copy. We want deep copy and then we'll come pick A sector creates shallow copy. That's why we have to create our own Coptic. A stripper here. So it is mended for here. It is not a choice. It is amended. Treat this compulsion. Okay, we have to We have to create copy Constructor, We have to create our own copy constructor here. Okay, So creating the copycat September till the structure So that struck Cherries festival. Same name is thick. Last name, same name as the last name. What it will take. It will take a student as input. So student s and then. But it will do It will copy in the age Andy name. So this addle age is as dotage and this Adul name is as dart name. Okay, so This is shallow Copy This is shallow PVR only copying the address. So this is how inbred copy constructor to certain. Okay, so this is in bed Coptic A separate. This is the court for inbred competence. Stricter. But since we have to create our deep copy since we have to create deep copy what they will do, we will make a new Eri and then we will copy the content. So this Adul name is new Cat Now what will be the Lent string went off Ask Dart name and we have to do plus one by Pleasant Because we have to copy Nell also And then we will use string copy function, stink copy function We will give this arrow name and s start name. Okay, so in this way we will create our deep copy. So this is the court for Deep Copy Deep Copy. Okay, now what will happen? So this is our name from the mean This contains that just 700 the values ABC the Anil Now we have our restaurant. So s one contains age Toby 20 and named Toby It 100 by 800 because we created our new Eri and then we cooperate The content and the address of this new areas it under. Okay, so that Neymar fasten points towards this memory location. Now let us talk about them. Copy constructor. So for corporate constructor, we are creating a new object with the name s too. So first off we will copy the edge so each will become 20 And then what we're drink do here is we're creating a New Aires So when you were, they will get created The sides will be five. And then what? We are going to Rubia copping the content. So ABC the Anil Let's say the address is 900 So this time the name of history's containing they're dressed 900 So if I will change the name off as to if I will make it s X then there will be no effect on the name off s one. So when we write as wonder displayed than ABC the carpenter where when we will write extra door display than XB city gone printed. Okay, so this is deep copy. And how we will call our constructor student as to input argument s one. So this s two will go in this and this s one will be as a perimeter. Okay, this Essen will be as a perimeter. Okay, so according to me, everything seems fine, but everything is not fine. Okay? Why does not Fine. There's a very big mistake that we're doing here is Let's try to understand what is the mistake that we are that I'm talking about? So what happened is when you late student s to s when? So this will go in this function of the copy constructor and s one. Well, come here. So a copy will be created, so over s so we can write. We can write this Linus student s is I mean, Dart s one. Okay. Essen from the mean is being getting corporate in tow. Student is And in the previous videos we have learned, whenever we write student his three closest one. So although this is copious entrant operator. But we know Coptic. A step that will be called here. We have already discussed about it in the previous videos, so copy constructor will be called here. Okay, so at this line, copy Constructor is being getting called. Okay. Why? Copy constructors being very girl because we are passing will lose by value. Okay, this is passed by values. And although this is not correct, this is north Correct? Why? This is not correct. Why This is not correct. Because that is not valued. Because as soon as we create our own copy constructor and bread, Coptic a strict is not available to us anymore. Just like as soon as we write our own default Constructor, that inbuilt default constructive goes away Likewise, As soon as we create our own copy Constructor, the in built copy constructor is not available to us anymore. So what will happen at this lane? We are calling copy constructor. So investors not available. So our topic a circle will be called. So this will call our own copy constructor. Okay. And then we will come to this argument And as we come to this argument copy, constructive regard called to copy the values from Essman Us. Okay, so in this way, in final clue will be created in financial will be created. Why? Because first of all, copy constructively to call here to copy the values from s one to s. And then when we will reach this argument than again copy constructively but called and other copy concert people because because we have write our own copy constructors, when will construct is not available to us anymore. So why, That's why Infinite Loop is here. So why infinite loop? Because we are talking about creating copy constructor. And in the argument off that copy Constructor, we need a copy constructor. Okay, I'm repeating myself. So we're creating a copy constructor and to create copy Constructor, we need to call biggest repairing the argument to copy the values. Okay, so what we have to do is we have to avoid calling this copy constructor. And how can we have worried calling this copy constructor by using passed by reference? Okay, so if you look here, there's no need to pass by value. Okay? Vita, call copy constructively. Simply can pass by reference because we are only accessing its properties. Were not doing anything extra VR only accessing the properties off student s. So why to call Copy constructor. Okay, So what will happen? We can also optimize it. How we can make we can make it a constant reference. We have started about this like if someone do this as dot age is minus one. So I want to avoid I want to avoid this line. I won't avoid this illegal changes. So to award this, a little changes begin pass. We can write Constant here. Okay, So what is happening? It is the meaning of this line is very simple. Student Constant reference variable s one is That s one. So this is this the me last one from me. Okay, so this s Is that offense variable to watch. Student Constant It is an offence. Very bad. Western constant. So this time copy constructively. Not because Okay, so I was in bed Copy constructed. Also take argument in this session. Then we'll copy. Constructor also takes arguments in this session, but the problem with inbred copy constructors, then bad copy constructively. Make shell a copy, but we want deep copy. Since we want the copy, we have to write our own copy constructor. Okay. - Okay . So Okay. So I hope you and destroyed this. Thank you 14. Initialisation List: Hello. Even so in this section we will learn few more important concepts off object oriented programming. So before starting to this class, let us try something. So when we right. So when we right in day five, what will happen? We will get memory block A and it contains the value five. Similarly, if I want to create a NVIDIA constant where total disinfects and constant B is a So I decide what will happen, I will get the memory block B and it will contain five. OK, so we can write constraint before in teacher or after in Pisa. OK, so that's our choice. Now, can I break this line into two parts? I can make the statement in tow two lines. So the first line is in a and the second is a is five. So at this land, I will get a and it contains garbage value. And at this line, I'm overriding the garbage value with the value five. Similarly, can I break this line into two parts and go to statements so the first treatment will be I'm creating in Peter Constant. So indeed, there constant be and its second lane I will corporate a value A So I displayed what will happen? I will get her memory block B and it will contain I've got basically you entered this plane . But we're trying to do here is we are trying to overwrite this garbage. Really? With the value five. So this line will through a center via because we can see here B is indeed a constant. We cannot change the value of being once it is assigned. So at this line, B contains the garbage value because this car based value and at this land were trying to overwrite the garbage were looted the value five. So we will get another at this line. So before getting a read this line, we will get better at this line. So why did this lane compatible through enter at this line? Because what we're trying to do here is we're creating impede a constant we're creating and bigger, constant and didn't visit. Constant contains a garbage value. Okay, so don't be a constant Convey cigar visual, basically that we loose useless for us. Okay? Since it contains the garbage value so it is used less for us Compiler will not allow us to do this. So what we have to do? We have to initialize the constant. We have two initial after constant variables at the time of its creation. Okay, so this line is correct. We have to initialize the constant variable at the time of its creation. Now, let us take one more example so and bias faith. So I will get a memory block. I ended convinced the value five. I want to create a French variable. So reference very bulgy is a So the name off this block is also Jay. OK, so both I NJ points to this memory location. Now, can I break this line into two parts into two? Statements to the first statement is create a difference Variable. And a second statement points toe j will point the way. Okay. So again, at what will happen, we will get a red Ghislaine. So, just like the constant variables, it is compulsory to give the value off reference variable at the time of its creation. Okay, so at this land, what will happen it will contain it will point to my garbage memory location. Okay, so come by level not allow us to do this. Okay? So for constant and for reference variable for constraint and for reference variable. We have to give their value at the time off their creation at the time of the memory location. Okay, now let's see in court. So I have a class here student. So the student contains two public properties each. And remember now my aim is very simple. But I want is what we want. This verse little number is said it cannot be changed. Similarly So what we have to do here? If we write b plus plus, then it will through other it will through error because bees in Peter Constant Byzantine constant. Similarly, Miami's was the value off roll number is it was the value of rule number. Is it? I cannot change it. So what we have to do? We have to make it. I am Peter Constraint So we can write constant before in picture or after in pigeon. So here I am writing Constant before in Asia. Okay, Now let us create objects. So student s one. Now let us try to change the values off a general number. Okay, so astronaut age lets it in and s when Dart rule number That's 100. Okay, so let s win this fight where it will happen at this line, there will be an editor because we are trying to change the rule. Um, but okay, so laters. First round off island. See that it? So would you indicate donated? Why I probably wouldn't run this file? Yes. Okay. Now we will run this file again. Okay, so we get another read this lane now let us try to understand vibe. You get another. So I displaying what will happen. D Ford constructor will be called default Inbuilt constructor. Okay, So defiled. Inbuilt construct level. Get called and what it will do. Age Total number. Bortolini said Toe garbage value. So a gentle number both contention garbage balloon. So this is tour intestine. They both contain garbage values. Okay, at this lane where time trying to do I'm making I'm overrating the garbage value off the age group in And yet this lane I am over writing. I am writing this garbage value and I'm trying to make it tender. But you cannot do this. Why? Because rule number is a constant If you see the class. If you shoot a class, we have make it our impeach a constant since the lumber isn't age a constant. Once it creates a value, we cannot overwrite it. So here we cannot overwrite this garbage value. But if you will see, we get an error at line number six via gate and a red line number six. Because what we're trying to do is we're creating. We're creating a rule number we're creating and Peter Constant which will contain the garbage value. So come by level not allow us to do this. So basically what come by level say if days NPR constant and dissent is a constant contains the garbage value than basically it's useless. It's useless to make a indeed, a constant. Okay, so that's why we will get a red line number six. We will also get another red line number it, but before line number it, we will get a red line number six. Okay, so it is mended due to initialize the rule number at the time of its creation at the time off memory allocation. Okay, so the one we're toe correct album. So the one were to correct Our court is what we will do. We have to initialize. So let's make it 100 here. Now there's a problem. So what is the problem? Suppose I have 10 strings. Then what will happen? All their 10 students will have the rule Number is 100 they cannot change it So obvious Lead. This is the wrong approach. This is the wrong mattered. Okay, so what we should do? So we're to initialized so that each object can have its different number. Each of their can have different all number So the answer is constructor like a stripper Because construct very school for each object and construct will be called on Libyans Okay , so there it does create a constructor So we will construct. We will create a perimeter ize constructor It will take a roll number is input And then well said Remember you are okay now They're desperate in this way CVR again getting another So let us try to understand via get another. So when I write and a and in the next lane if I write equals five So at this land, what will happen so before? A I am not writing in teacher before I am not writing the Asia So what does this mean, this means that is already created in the memory is a lyric it into the memory which contains the garbage value. And we're tryingto over at this garbage value. Okay, now see this lane, Rory Number calls are we are not writing in teacher before rule number. So that means rule number has already been created in the memory and it contains the car best value. And here we are trying to put our are in dural number and the lumber contains garbage value . Since the lumber isn't is a constant, we cannot override garbage. We live with that. Okay, so that's why we are getting added at this lane. Okay, So what happened is s one is we enter the constructor as soon as we reach line number seven . Rule number is already created in the memory and it contains garbage value. So what is the solution? The solution is we have to initialize the rule number at the time off memory location. We cannot do it inside the constructor because as soon as village inside the constructor memories allocated and garbage very loose present at that memory location. Okay, So what we can use here is there's something called initialization list initialization list can help us here. Okay, so let's one again. See, what is the problem? So the problem is very simple. As soon as we reach lime number seven. As soon as we reach inside the constructor. The rule number, this rule number property this rule number eight a member has already been indicating that the memory and it contains a garbage value. And at line number seven at line number seven, we're trying toe over. Eat this garbage value with our okay, and we cannot do this. Why? Because rule number, isn't it a constant? We cannot change the values. We cannot change the value for a number. Okay, so the solution is initialization list. So what initialization will do? It will initialize the constant properties at their time off memory location. Now let's see the Syntex. So, first of all, this is wrong. Let's coming toward discord and this intake for initialization list. Certain text for using initialization list is very simple. Put a column and then name of the name of the perimeter. The argument which is our okay. And that's all. OK, so let us in this file. See now this time there is no other. Okay, so what is happening here is so I told you when we will reach line number seven through lumber property is already been created in the memory. Now see line number six. So what will happen? I like So what will happen at line number six? We can assume that rule number is given memory. At line number six. Rule number is given memory and at the line number six were writing this statement. So this rule number will contain are Okay, so this wave we can initialize our private property is weak initialized ever constant private properties. So at this line, we can say what is happening. Constant in de Gier rule number equals are so this is the meaning off the slain. Okay, memories being a located total number and the R is initialized. And this is and the rule number and the real number. Private properties initialized with our Okay, So this is the use off initialization list. Okay, So what we can do here is it is not necessary to take my auntie jazz input. We can also hurt. The value is we can also write it like 100 but Also, this is off no use. This is useless by useless because every object will have the rule. Number 100. Okay, every object will have rule number 100. So obviously this is useless now What if I take to perimeters has import a general number, so intra number and the second value is into age. Okay, so rule number art and then comma age is a Okay, So So we should know this. Here it is. Initialization list can also be used for normal variables normally and teacher variables. Okay. It can also be used for normal properties. So it is not necessary. It is not compulsory that in each elevation list can only be used for constant later members. Okay, initialization list can be used for normal data members. Okay, Now, what will happen if I change the argument name to age? So we have to write. Is it Okay, so this is correct. There is no need to right this way because it is very clear. It is very clear here that this age means this at our age. And this age is the argument age. So there is no confusion here. Everything is very clear. So there's no need to write this here. Okay, so there's no confusion. Since there is no confusion, we do not need to write this. Okay, so one more case where initialization lists can be used to use. Suppose we have a reference variable. Let us have a reference variable. Okay, so their offense Variable x. So this X is each defense. He's a reference variable. Okay, So initialization list can also be used for reference variables to what we want is our dream is very simple. So if we want this So this is our him. Okay. But it cannot write like this way because this each if you see here, this age can be argument age so days a confusion is since days of confusion. We have to write something like this. This Edwidge. So at this lane there was confusion that age can be the argument age. So to avoid the confusion, we will write this. Okay, so writing this is mended three here and I told you so. I already told you before. Just like the constant variables at a friend's variables have to be initialized at their time off its creation. Okay, so it is mandatory that we have to use initialization list for reference variables. So x and the really will be this Edwidge. Okay, Now let us in this file. Now, obviously, as we write our own better my best constructor before construct place not available to us anymore. So we have to use parameters, Constructor. So let's say the rule number is 100 let the ages stone. Okay, so you stayed. This land will not work because the number is a constant property. Okay, now that doesn't this file, and they should be No either. Okay, so have a court is anything? There's no added. So what we learned in decision. There's something called initialization list. And what is the purpose? Off initialization list. The purpose is very easy. It initialize constant properties, constant data members, constant properties and the references, data member and reference properties at the time. Other time off memory location. Okay, so I hope you haven't destroyed this video. Okay. Thank you. 15. Constant Function: Hello, everyone. So in this video we will learn about concerned functions. So, before starting constant functions, let us first to review our court off fraction class that we did in the last session. Okay, so we have this faction class. This is true properties, numerator and denominator and both the properties are private. Then we have our default constructor. And then we have a perimeter ize constructor which takes numerator and Dermot resin poured . Okay, so we made this forward functions. These four functions were not present earlier but now we have made it. Why? Because the numerator ended amid the property. Both are private field. So if you want to exist the numerator and the denominator, we have to make and get trendsetter functions. So we have a function. Get nominator Italy done numerator. Similarly, we have a function Get the eliminator. So this function returns to denominator. Then we have a function start numerator. It will set the numerator said Lemaitre. It will said they're denominated. Okay, And then we have brain function simply five function, add function and multiply function. So all of these functions were given the last class. We just created this four new functions. Okay, get trendsetter functions. Now we have two objects. Affection F one infection after. Okay, so it really doesn't picks for career dinger? Indeed. A constant. So this in Texas, Quite familiar. We have quite family with this index. So in days faith. Now, if I want to create an vigia constant and cause to be equal C So this is the Syntex for creating and video constant now, similarly, we can create object constant. We can create constant objects. So it's in Texas. Fraction then constant keyword F three. Okay, so this is a Syntex for creating a constant object. Now, if I do B plus Plus here. This is wrong at everybody here because we cannot change its properties. Similarly, we cannot change the properties off F three because it is a constant friction. We cannot change the properties off F three. Okay, so now let's in court. So let us make a constant object. So fiction constant keyword F three. Okay, now let us try to print the values. Let us try to print its properties numerator and denominator. So see out after dot get denominator. Sorry, We will first print numerator. So, Newman, you're dead and now they're dead Sprint denominators. So I have to dart get denominator. Okay, now now let us try to change the value off. New minute also. So f three dot sit numerator and let us give the value then. Okay, so let the straight to a place where it will be our output. So we are creating a constant object f three. Since it is a constant object, we cannot change its properties. Okay, but in the get numerator, So dysfunction is good numerator So in that get numerator and get the number function. We are not changing the property. These function are just returning the properties. Okay, so I believe we can call these functions. But see this Lane said numerator, so dysfunction will change The really off numerator says this function changes a really often emitter. We cannot call this function okay? We cannot call a function which changes the properties of the object so idly these two will run fine and we will get better at this line. We will get a read this line. Okay, So what if I will command the slain? Then what will happen at this line before constructively called the Ford constructor that we have created. So our default constructor will be called and numerator and denominator property will be sold to the garbage values. And when we are printing the numerator, the denominator loose, We will get garbage and God beach. Okay, Both Newman attended a material. Continue our values. Okay, so let us turn our file. I believe you will get a red line number 12. So in order to see that it Okay, so let's in this file. So we are getting out ahead because new military za private property you have to call function, get no money that Okay, So now let's in this file. So I believe it should happen. We should get a red line number 12 but we're getting a red line number 10 now. Like to see that what are theirs? So we are getting error, get numerator, get dominator, and certainly little basically we're getting a read on all the three functions. We are getting better for dysfunction. Get numerator! We're getting editor for this guy, denominator, and we're getting error for certain emitter function. Okay, we have discussed we should get a read this line, but we're getting at all the three functions. So that means there is something wrong with our approach. So our approach is wrong. Our way of thinking was wrong. There's something is Okay, Let us try to understand what is wrong with our approach. So actually what happens is for nuclear it of constant object. So friction constant f three. So whenever you create a constant object, we cannot call any function through if three we can recall any function treff tree because compiler is worried about the function that you have called. But if inside that function with some changes to our properties, there is a problem. OK, so basically compiler won't allow us to call any normal function through f three. Okay, so compiler will not allow us to call any normal function through a constant object. We can only call constant function through constant objects and north any normal functions . So now the question came, What is a constant function? So what is that constraint function? Ah, constant function or do its function there Do not change the properties of the object. Okay, So constant functions Rich does not change, which does not change any property off the current object. Okay, so constant functions are those functions. We do not change the properties of the object. Okay, so I hope you haven't destroyed the problem. So the problem is compiler will not allow us to call any normal function because the object is constant. Similar living cannot call dysfunction because compilers worried about us. Okay. What if inside the garden a motor function which is the value of denominator or numerator gets a compiler won't allow us to call any normal function through a constant object. Okay, so we have to use constant functions. Now let's see how to make a function constant function. So see, we ever get numerator function. So what this get new motor function is doing it is simply returning the new military. It is not changing the value off any of the properties of the object. So I'd leave the sure mark this function as costume function. So how to mark a function? A constant function. We simply have to write a keyword constant. Now, dysfunction is a constant function. Okay? And F three can call this function similarly get diameter function. This function is only accessing their denominator property. So we can also make this function as constant. Now the constant object which is F three, can call this function. Okay, now let's in this fight. And now we will run this file. Now, if we will run this way, we will only get better for certain numerator function and not tire. Forget denominator and get new Britain Good denominator function. Okay, okay, so let's run this file. So this time we are getting an editor at random Birtwell. So if you will see that there. So here there is only due to certain numerator function. Okay, that is only due to set numerator function. So what? This time we can call, get no better function and get the motor function because both the function has been marred . Best constant function. So compiler will allow us to call this functions. Okay, So overcome by level, do when we're calling this function, get numerator so compiler will go to get numerator function. So where is good? New motor? So get no combine level Reacher getting able to function and dysfunction is constant. So combined will allow us to call this function Similarly, when you call this function Gardena metal so compatible reach get the normal function. Since this function is a constant function come by level. Allow us to call this function and for certain numerator function come by level. Reach certain motor function. Since this function is not constrained, compiler won't allow us to call this function. Okay, now. So tell me whether said new motor function qualified to a constant function or not. So the answer is said new motor function cannot be a constant function because it is changing the property. Okay. No, overt. If I make this function a constant function, Okay, Eileen, they should not be a constant function now. What if I make this function of constant function were to happen Now let us turn our file. See, we coordinated. Why we got another. Because here we're trying to change the value off numerator. And since the function is constant, we cannot do this. Okay, so let's remove constant here. Now, let's and this file again. So this time our file is running. There is no it. Okay? Now said the limiter function can be a constant function or not. So same reason assert numerator started. Older function doesn't qualify to be a constant function because it is because it will try to change the value of denominator. Now, brain function at the stockyard brain function Can brain function qualify for a question function? Yes, it is because it is only accessing the properties. It is not changing the property. It is not trying to change the property. So brand function is a constant function. All right, the struggle simplify. Can it be a constant function? So the answer is no. Why? Because it is changing the value off because it is changing the properties. So it cannot be a constant function. Our function. It is also changing the properties Numa trended limiter, so it cannot qualify for a constant function multiply function. It is also changing the numerator and the denominator, so it cannot be a constant function. Okay, so only print function, the only brain function and these two functions qualifying for the constraint functions. Okay, So whenever we are working with the classes and object whenever we are working with the functions, we should look carefully. If a function can qualify for a constant function, then I believe we should make them a constant function so that constant object can call dysfunctions. Okay. Thank you. 16. Static Members: Hello, everyone. So in this session we will learn about static properties of a class. Let us take an example. So I have this class student. So the student class has three public properties rule number, age and told assurance Soto industrial and Saudi told the number of students present in the class. Okay, So whenever we create a new student, what will happen? The only off road Austrians will be incriminated by when initially we can assume that the value of total surveillance are zero. Okay, so when we create an object so in a get an object student s win, what will happen? All the three properties will be copied So rule number age and told Austrians Now at this lane, the fall constructor invented the file constructor will be called so roll number will contain garbage value Age will contain garbage value and told the students will contain garbage value. Similarly, if I create another student story industrial so again, all these three properties will be copied so students struggle number surrenders to age and story in best to daughter students. So at this lane, invert the file constructively. We called several number will contain garbage value age will contain garbage value and they told us to reinstall. Contain guard base value. See what happening here is. Each student should have its own. The lumber each student should have. It's on age. Each student should average on total students. Now this is wrong. This is a very veered statement. Okay, so each student will have its own the lumber. This is correct. Each student will have it on age. This is also called but each student will have its total story. It's not. This is kind of weird. It's a very veer statement. So the property total students, the property total students This property is a combined property off all the Austrians and it is not the property of passing the student. Okay, so the value of total student should be seem for all the objects. It will never happen that for storing that's when the value of total through insistent for this to tortoise to inside 20 And for the street orders to enter 30 it will never happen. So the value off this property the value of the told Austrian property will be seen as a number of students creator So this property does not belong to object. This property belongs to a class. Okay, so the report, the value of total students at one place inside the class and whoever wants to excess the total student, it will go and ask the class. Okay, So the properties, which belongs to a class we declared them started using the static. Gifford. Okay, So the properties, which belongs to a class we declare them started using this tactic given before the in teacher, we will write. Started covered before the in teacher. Okay, So what are strategic properties? So static properties at those properties which belongs to a class. So these properties belongs to a class and not a single object and noticing the student. Okay, So what will happen to the static properties? Separate copies north catered for each object. Okay. So we can access static property only using classes. So what we will do? We were right static and told us trillions. We will update this line and will use the giver static and two restaurants. Now, what will happen if you will create an object student? That's one. So whenever we create an object, only the nonstrategic properties get copied. So roll number and age The boat are nonstrategic properties so by default the properties are known static. So whenever we create a new object on leader, nonsurgical produced will be copied Sorrow, number and each these two properties will get copied toward restaurants will not be copied and it will continue our base value because their default constructive will be called. Similarly, if you will create another object, let's call it a student s too. So only the non skeptical produce will be copied straight. The properties are not copied. Started properties belong to class. So at this land default constructor will be called and roll number and age contains the garbage Will you? Okay, So one thing to remember is Onley the copy off non static property. The only copy No aesthetic properties. Okay, so separate copy is not created for each object When we declared them static Okay, so student told the students will not be copied. So what will happen due to restaurants? So we have a student class. We have student class This student classes three properties roll number which doesn't have any value age which does not have any value and it will have total students now Let's say the value is 20. Okay? So told a student now is a part off student class. So we have this student class. Okay? Now how can we access the rule number? Okay, so two accessible number Venuto, give it our object. Okay? We can access rule number using an object so too accessible number. We will write object name Dart Rule number vie vineyard object because rule number is a non static property rule number is a non static property. To access a nonstrategic properties, we need object to assert order lumber similarly extra total number and so on. Ok, but how can we exist? The two restaurant property so told us when properties aesthetic property. So if if I will write if I try to put the value s one dot toward restaurants what will happen? So obviously this line is wrong. Why? Because if we'll see it if you will see s one. So s one doesn't have any property to restaurants. So obviously this line will through a center. Okay, because Essman does not have any property total students. So this line is wrong now how can we access to restaurant property so toward restoring properties a start. The property. And I told you started property belongs to a class. So if you want to access turtle restaurant property, we have to access it using class. So first we have to write class, name, student, then score Resolution operator. And then the static property. The name of districted property. So this is last name this operator. We call it score resolution Operator scope resolution abated. And then the name of the aesthetic properties. So this is our static property total students. Okay, so this is how we exist. This is how we can access a static property. Okay. Using the class using the class. Okay. Now, how to initialize abstracted property. So started property can only be initialized outside the class. Okay. Started properties are initialized outside the class and the same texas. Very simple. We have to write. Indeed it. We have writing teacher here, but we will. But we again after, right and teacher, then the name of the class then scored Resolution operator than the strategy property name of the static property and then its value. So this is how we initialize a class. This is how we initialize a static property Okay, So started property can only be initialized outside the class. So let's in gold. So, first of all, we have to make this property static property. Because this property is combined for all the objects. It is not. It does not belong to us in restaurant. It belongs to a class Now. I told you, if you want to initialize the strata property, it can be in its list only outside the class. So we have to write in pizza again. Okay, We have to urgent danger again. Then the name of the class which is student than school resolution operator Column column Then the name of the property. They know name of this tragic property. And now it's value. Okay, so initialize static. Data member. Okay, so you have to remember it that we can only initialize distracted properties outside the class. Okay, Now that does create some objects. Student test one. Now what will happen before constructor will be called. Now let us try to print. Now let us try to print it's rule number 10 days property. So it's one dart rule number. We can accessible number because it's a public property and similarly let us try to print its age. Western dotage and lane. Now let us try to print the value of two restaurants. Since told a student deserves stated property, we will access it using the class. So class name, school resolution, operator, and then the name of the street to grow pretty. Okay, So what should be our output? So it this land, what will happen? The fall constructively called. So roll number and age both contain the garbage value. So garbage will it printed. Then again, garbage will be printed. And what is the value of total students? So if we see this court, the value of total students, we initialize or 20 so it should be garbage. You look average value and zero. Okay, so let s win this fight now. We will win this fight. So God, base value, garbage value and then zero. Okay. So what good is working? Fine. Okay, so everything we discussed is working fine. Now, what will happen if I write? If I am trying to access the total stolen property using the object, then what will happen? Okay, So, airplane number nine, what will happen? What will be our output? Okay, so let us in our file let us rent and see where two year output. So that would produce coming out to be zero. It's very strange that produce coming out to be zero South Accord is working combined list nor throwing us any added. But logically, this is incorrect. Okay, logically, it's incorrect. But come violates allowing us to do this. Why? It is logically incorrect because student s one doesn't have any property with the name told the students. Okay, now what will happen if I try to change the value of total students? So s one Dart George. Historians, Let's make it 20. Okay, Now let us create another object story intestine, and let us trey to print the value off toward the students using the object as toe so extra dart the restaurant's So what I'm doing it is I am trying to change the value of told Australians using the object s one. And then I'm creating a new object, a new story, intestine. And then I'm trying to print that told the value of total student using the object as to so logically this line is wrong. Why? Because storing one doesn't have any property with the name for a student. Similarly, this land is also wrong. The bird Kambala, allow us to do this. Okay, so I see the value of two restaurants is 20 If we access the two restaurant property using the object as to so why it is coming out to a 20? Let's see So I told you the property total student This is a static property. It will not get copied. So we have student class inside the student class We have this property toe restaurants. So there is only one memory block. There is only one Okay, it will not get copied. So at this lane I am trained to excess total student properties over object lesson will go . It will go to class. It will reach classes, religious trained class and it will try to read its property. So initially it was zero. So that would put a zero Then I am changing the value of total students. So s when it will reach the student class and it will change the total stolen property which is? It now becomes 20 them career. Then I am creating a new object as to as to go toward a student So the object as to reach the class and it will read the told a student value which is 20 so 20 will get printed and similarly where I am printing the value of two industrial which is 20. Okay, so we can change. We can change the value off strata property using any object. Okay, Using any object, we can change its properties. But a logically it's incorrect. Okay, logically it is incorrect. But compiler, allow us to do this. Okay? But we should not do this if you want to access the static properties Excessive using the name of the class. Okay, so logically it is incorrect. But Kambala, allow Western do this. Okay, now let's see. So as you're discussing the starting of the video So as we're discussing the starting off the video album is very simple. As soon as we create a new object, the value of total strain property should be implemented by one. Okay, If I create a new student, then the value of P s total soon property Wilberto If I create tense rinse the value off total certain property will Britain Okay, so how to do this? So we know how to initialize toward restaurants how to initialize a static property. We know how toe xs aesthetic property but we do not know how toe oblate aesthetic property . Okay, so what we can do is we can we can take the help of a constructor. Okay, So what will happen whenever we create object constructively? Ba called. And inside the constructor, we will write to restaurant plus plus Okay, So I am planning to create I've constructed so we know when of the object will be created constructively but called. And inside the constructor we were right to restaurant plus plus Okay, So in this way the value of to illustrate the property will be implemented. Okay, so let us believe it. All discord now let us create students So a student as to now let us create more students Student as three as food s faith. So after grating Feist rents, I am trying to print the value off toward Austrians. Okay, so what should be our output? Let's see. Okay, So why it is coming out to be zero Because after doing changes. So this file after doing genius Travis, fight before God during this file. Now we will win this fight. See now, doubt Produce coming out to a five by five. Because because first the constructors coiled forced to investment so to restaurant become one. Then the constructors called for this to so the value of holster and property becomes too. And then the constructive will be coiled for student s three s four in this five. So in this way, the value of total student property became five. Okay, so just like the starting greater members, we can make functions static also. Okay, We can make static functions also. So I suppose I a function in the ghetto number. I have function Guettel number. So what dysfunction will do? It's simply wilder. Dandy roll number. Okay. Now dysfunction get really embodies object dependent function. This function depends on the object, and object will call this function so by default. Dysfunction is a non static function. So by default every function and by default everything. Remember they are non static. Okay, so, by default, this is known static. Since this function is no monster taken object will call dysfunction s rendered Guettel number Esther George Guettel number. So we need an object to call this function Okay. Now what I want to do is now let's make this property a private property. Now, since this property is a private property, we need a gator function to excess this property. So let us create our getter function. So in get the restaurant's to what dysfunction middle. It will redone. Told us, Arendse. Okay, so we will make this function as static function. So after eating the giver, start IQ now, dysfunction belongs to class. Object will not be able to call this function. Okay, so s. And don't get to restaurants s road. Get restaurants. These are wrong how we will call dysfunction. So I told you dysfunction belongs to a class. So that's index to excess. Frustrating function is the name of the class school resolution operator and the name of the function name of the starting function which is get total students. So this is how we will call this function if you will right s $1 to get towed restaurant Now, this is logically wrong. Why? This is logically wrong. Because dysfunction is a static function and started means this belongs to class and not to an object. Okay, Now there are a few properties. There are a few important things that we should know about the static functions. Okay, so few properties of distracting function notes. So the first thing So the first thing is static functions can only excess strategy properties, whether it is a data member or a function okay, started function can only exist. Static properties, Whether it is a data member or a function, we cannot use non static function. We can reduce non straight to remember inside the static function on. Also, we cannot call known static functions. Okay, so started function can only exists. Starting with the members start to greet the members and can call only static functions. So, for example, get to a restaurant. This is a starting function. So if you will right here, they're done age, then This is wrong. Everybody here because the first property of striking function is they can only access starting later members and they can only call started functions. Okay, Another second. Property off the Strait of functions are static function. Do not have access. Do not have this Gifford started function Don't have discovered okay because we do not call straight to function through an object So what happened is this is a normal function. So to call this normal function, we need an object. So s $1 get rule number. So this object will be stored in that this giver off this function now when we have static function. So for calling the static function, we do not need an object. Since we do not need an object, we do not need this operator. Okay, so these are the two very important properties of static functions. First strategy function can only have access off the starting grid A members and they can only call started function. Second properties starting function do not have this keyboard because we do nor to use object to call dysfunctions. Okay, so this is all about static properties of a class. We can make a deal, remember, static and we can also make functions static. Okay, static means these properties belongs to a class and not to object. Okay. Thank you. 17. Operator Overloading 1: Hello, everyone. So in this video we will learn about operator overloading. So operator or lording means start We can extend the functionality of the existing operators such that it will work for our user defined classes also. So in the last session we created this fraction class. Now what I want is so our aim is very simple. What we want is f three is f one blessed after I want to do something like this. So currently if we will write this treatment than this treatment is wrong. Why? Because the plus operator is not defined for our fraction class. But if I will write N c as a plus B then this line is right. Why? Because this place operator is defined internally for doubles and foreign teaches. Okay, so this line is wrong. Why? Because the plus operator is not defined for our friction class. So our aim is very simple. We wanted to make this line book. We wanted to make the statement book. Okay, so what we want is we want to extend the functionality of this place operator. We want to extend the functionality off this place operator so that this press operator can work for our fraction class. Now this process is called operator overloading. Okay, so now we have to learn how to overload operator. So let us see this aired function. So how we we call this ad function? We will call it with the help of an object. So f one daughter and in the argument will pass affliction after. So what? It will do it to a ladder to numbers F one. It will have two fractions, a friend plus f toe and it will store the result in F one. Okay, so this is where discord will you now. Letters first changed the functionality off this air function. So what decided function will do? It will have two fractions F one plus f two and it will store the result in new friction. It will create the new fraction and it will return new fraction. So how we will call this function Fraction F three. We will call this air function F one dot aired and it will take after s argument. Ok, so this is our him currently. Let us change. Let's first change the functionality of the art function. Okay, So what does that function will do. It will create a new fraction f three and it will return the new fraction F one and F to both will remain unchanged. Okay, so how can we do this? So let's see. So first off oil, let's go pee dysfunction. Okay, so let's make change in this function only. So what will the return type now? The return type will be a fraction, because we will return a new fraction. Okay, so can't leave. What we're doing here is I am changing the numerator and the denominator affection F one. So let's coming out this cold. So what you have to do, we have to create a new friction, and then we will redundant friction. So fraction f new. Let's name it F new. So fertile with a new militar. So new monitor will be a new um and their denominator will be calcium. Okay, So what will happen at this lane? Better. McDade's constructively because and our object will be created. Okay, So paramount priced constructor cold. And now our objectives Ready? Okay. So after doing this, we have to call simplify function. So currently, if so, currently, the simplify means this era simplify. So this simplify function is being called on F one. So we have to change it. Where do we do? We will, right after New Dart simplify. Okay, so the new objective new So the new fraction, if you will get simplified, and then we will have done this new flexion so it done after new. Okay, so this is all that we have to do. Okay, so let's test our record. So currently we have these two factions flexion if one infection after. Okay, so let's make a fraction f three. So this fraction F three is the addition off F one F two so f one not add, and we will give f toe. Okay, so now let us sprint F one after a nifty so f one dot print after dark print and similarly f three door to print. Okay, no, let's turn our program. So first we will compile this fighting, and now we will win this way. Okay, so there's something wrong here, and it was nor declared in this scope. OK, Okay. Sonali doesn't this file and now we will win this way so we can see here the value of have fun enough to remains and changed. And this is our result after which is the tradition off fraction offended left. Okay, so now what I want. So our aim is very simple. What I want to do is I will create a new fraction fraction effort. So I want to create a new fraction fraction of four. And I will write F one plus f toe and the result will be Samos Fraction F three. Okay, so I've warned the same functionality. So this place operate ever do exactly the same book which the air function used to do? Okay, so the functionality will be same, but I won't toe use bless operator instead of this air function. Okay, so let's see in court how to do this. Okay, so let's copy their function. So what I did is I only just copied their function now how to use operator overloading. So first we have to write the keyword operator. So operator is the key word. And then you have to write the operator, which you won't overlook. So we want to overload plus operator. So without space, right? Plus. Okay. So that's all. You only have to do this much, work everything the functionary will remain the same. You just change the function name to operator keyboard and then plus Okay, So in order to do anything extra so let us create and a fraction fraction therefore so affectionate. Four will be f one plus after. So if one place after. Okay, Now let's turn our fight. So first we will end this one and no, we will end this fight. Okay, so before God to print therefore salute spent a four a four dot print. Now let's in this way so we can see here a four years old. So 35 by four so of accord is working so we can see here. It is very easy to overload, Operator. Now let's see how it is working. Okay, so you see this lane, What will happen? F one dot ad f goal. So this everyone will go in this this giver of the air function and this after it's passed this argument. Okay, now I see this lane. If when bless after the open end on the left hand side of the operator, this will go in this function, this giver off the dysfunction and after we'll go in the argument. Okay, so the left hand side opened will go in this and the right hand side argument will go in the argument and which function it will call it will call the function operator. Plus So operator plus function will be called. So this will contain F one. And after we'll be past this argument toe dysfunction operator plus function. Okay, so now let us overlord multiply Operator also. So what I want is I will create a new fraction fraction f three and destruction of three will be the multiplication off to fraction F one and F toe. So we will overlord this much pay operator So this f one will go in this and after will be passed as argument similar to this similar to wear function. Okay, we do not need to pass to arguments. We just need to pass one argument because the other one will go in this. Okay, so let us overlord demand to play operator. So this is another. When you play operator so over to Littleton type returned, I will be fraction because we will create a new friction. And then we will return that faction soldier and David Lee Affection then the key word operator and then the operative. It's we won't overload. So we want to award multiply operator somewhere to play. But it will dig. It will take affection as input, affection If toe And then when we were little we will kill clear the numerator and a denominator so into new monitor which is F one numerator What we can write this Erin emitter Multi Play the numerator off f one Sorry, my opinion paragraph after so after dark numerator Similarly in the fiscal greater diameter So denominator is do a minute but off f one what we can write Dissenter Denominator My reply by their denominated off after Okay, so now let us create new fraction which we will have done So Reflection Let's name it f new So the numerator will be in And the denominator is d again Copy Constructor. Sorry again. Parameters constructed will be called here and then we have to call simplify function. Okay, so the functionality will remain the same were falling this only Okay, so the functional level during the same Now we have to call simplify function. We have to go simplify function on the new object f new. So we have to rate f new dart. Simplify if you will simply right. Simplify then that means this air simplified. There simply were function. We got called on F one, but we have to call on F new. So after simplifying the leader, done f new. Okay, so that's all we have to do. So what will happen when we will? Right Infection after three is F one multi play after So the left hand opened. The first opened will go in this So this numerator means f one dart numerator What? We can write the center numerator and this F toe will go in the argument. Okay, so this is how we overload multiply operator. So this is how the overlord multiply Operator. Now let us try to overload one more operator which is equality equal to So now what we want is I want to overload this operator equal ical operator. So what this cyclical operator will do? I will give two fractions F one and F two and if the two factions are equal, I will print equal If they're two fractions are nautical. Then I will print nautical. So in the main function in the main program. The syntax will be if fraction F one equals equals fraction f two Then we will see out equal. Otherwise they are not equal. So in the else in the else part, we were right Not equal. Okay, so over to the return type. Okay, so first awful. This thing will go in the dysfunction, this giver of the function. And after we'll go in the argument and which function we will call, we will call the function with the name operator equal equal. Okay, so let's see in court. So first off, all over Italy with a return type return type will be bull because we will return through Wuerffel's Sobule. What will the name First of all, we have to write operator keyword then the name of the operator which we want to overload. So we want Oh Lord equal a cooperator. So it will take one faction as input fraction after because the first fraction will go in this and then we have to return either true or false. So when the two factions are equal, when the numerator and the denominator both article, then we can say the fractions are equal. Okay, so numerator and denominator bottle vehicle. Then we will say the two factions are equal. So when you monitor off if one equals equals, numerous drove have to and do. No matter has to be quick. So they nominate that off If one equals equals denominated off after so after dark Denominated. Okay, so So this condition. We like the bill true or this condition will either be false so accordingly wilder than true or false. Okay, so that's all. Now let's in this way. Okay, so there's something wrong. Okay, so there's a spelling mistake now. This is right. Where is compiled? A fail. Okay, so now we will test our multiply operator and our equal local operator. OK, so we have protest two things. So let's make let's clear deflection fiction If faith, which is the multiplication off fo infection and left affection okay. And a five door print. And now we have to test our equivocal operator. So if f one equals equals f two see out equal, it's Nordic quick. Okay, so that's all yours. An hour fighting. So this is our f three and this is the way before. And this is our Fife, So I five Is the multiplication off a friend of too? So I hope the answer is right. And then a friend after one article. So that's way our POTUS nautical. So if I write f when Nikolic olefin when the output will be equal Okay, so let's see. So this time our political because f in a different boat I seem okay, So that's how the overlord operator. So our work is not done here. Our work is not done here yet because we have to do some optimization. Okay, so what kind of optimization? So if you remember this air function, this air function is taking f two by reference and also constant reference. So first of all, by reference violated by defense. So to avoid calling copy Constructor because we do not need to call Copy Constructor and by Constant. So we need constraint to avoid legal changes enoughto Okay, this is our plus operator. OK, so here we have a real and optimization constant defense. Now can we do optimization? So this is my to play and or pretty much pay. So here we should pass by reference. Okay, constant reference because we do not need to call copy constructor here. And also we want to avoid legal changes. Okay, so that's why question defense. And similarly, we want to avoid calling copy constructor, and we want to avoid any legal changes. So constant reference. Okay, so no. One more thing now we have No, we know about constant functions also. Okay, So what are constant functions? Constant functions at those function that will not change the property off the current object. Okay, that will not change the property of the current object. So let's say this function equal, equal, so well, dysfunction changed the property off F one. Okay, so no, it is not changing the property. So this function is a constant function. So Mark dysfunction is a constant function. Okay, Now, let's see. Dysfunction mostly play function, so this multiply function changes the property of the current object. So the current object is F one, the object which is calling the function so numerator and denominator. No, it is not changing. It is creating a new flexion. Okay, so dysfunctions qualifies to be a constant function. Now, let's see this multiply function. So this much deploy function is changing the numerator and the denominator off the current object. So this multiply function is not a constant function. Let's see the plus function the operator plus function. So this function is creating a new fraction. And it is changing the properties of the new fractions. It is not changing the properties of the current object. Okay, we have commented out it does not changing the properties of the current object Since it is not changing the properties of the current object. This is also a constant function and similarly, this is also nor changing the properties. So this is also a constant function. Okay, so everything is working fine. Okay, so in this video, we always ordered three operators plus multiply and equal ical operator. In the next session, we will overload somewhere operators. Okay. Thank you. 18. Operator Overloading 2: Hello, everyone. So in the last session we learned but operator overloading is and we always ordered three operators plus multiply ecological operator for our fraction class. So I hope now everyone understand what is open toe loading and how can you overload operators So in decision we will overload few more operators. Okay, so first of all, we will overlord plus plus operators. So in this session we will overlord plus press operator So there are two versions off plus precipitator when it's pre inclement and the other one is posting Guimond. So I hope everyone knows for this there difference between pre and post increment. So in this glass they will focus on being agreement. Okay, so in this video, we will cover Bring Kim it in the next we do we will try to cover post increment. Okay, so let's start studies class. So when I write, it's taken example So when I write, entire is five and I bliss bliss And if I tried to print the value If I So what really are output? Sorry, I will do plus Plus I am because in this video we're trying to cover the increment So our our portal basics. Okay, So what will happen at this line? I will get a memory block. I and it contains the value five. So, plus Plus, I means make the value six. And then we will print the value six. Okay, so now we want to overload the plea agreement operator for our faction class. So I just take affection. So the district affection F one. So affection if one the value of new military distant and the value of diameter is two. So when I read plus plus F one. So what will happen then? My do bless one which is then place to by dough, which is 12 by two. And then we will call the simplify function, so it will become six by one. Okay, So if you remember in the last session, we overloaded press operator, So f three is F one plus f toe. Okay, so if you look carefully, this place operator is a binary operator. So what is a binary operator? Ah, by the air operator operator which needs to or parents to do this work. Okay, Which near toe prints to do its work. So in today's class, we are covering pre increment operator. So pre increment operator is a unity operator. So I unity open it dead needs only one opened to do its work. So in this case, what will happen? F one will go in this and after will be passed this argument. Okay, but for the case off plus plus operator since it's ah, unity operator F one will go in this and we don't need to pass anything in the arguments. Okay, so let us try to Overlord let the straight toward the increment of later. Okay, so let us see in court. So what is the return type? So the arable lording very inclement. Now over to you return type of the function. So we are not returning anything. So for now, let s assume the return type is void. Okay, we will do changes in diffraction only. So for now, letter says young Britain type is Wade. Okay, then we have to write off the keyboard and without space the operator which won't overlord So plus plus, as we discussed, we will not take any fraction as argument and no, let us change the numerator. Ok, so and when we do plus plus everyone on Lee. The numerator will change. Its A numerator will become. Nobody did bless Denominator. Okay. And then demented will remain same. And then we have two gold simplify function. Okay, We have to go simplify function, so simplify. Okay, so let's see how it will work. So I will call the fraction I will call dysfunction plus plus F one. So let's say numerator and the denominator is 10 by 2 10 and two. And this is my reflection f one and the address is 700. Okay, so at this land, what will happen? This will contain at just 700. And when I write new military's new multiples, demeanor, denominator, So it will become 10 plus two and the inimitable remain the same, which is two. And then we are calling the simplify function. So if we call the simplify function on 12 by two, it will become six by one. Okay, Salva Cord is working fine Now let us best of accord. Let's first comment out everything. No letters first tried to print devalue off F one So a friend or print and no, we will do being agreements hopeless place F one and then we will again. Print devalue off F one. Okay, so let's in our file. So first we after in this and now we will end this. So the output is six by one. Initially, it was turned by two. Okay, so 10 by two plus one it will become pulled by two. And then the simply where function sour out produce six by one. Okay, so our court is working Fine. Let's analyzer a bit more. Okay, So what will happen if I had? I'd if I had I'd And I is five then Can I write into J is less Plus I okay. And then if I had tried to print the value off i n j c out I and C l g So what do lower outputs are? Output will be six Sensex So at this land what will happen? I will get the memory block I and it contains the value five Then we are doing plus plus I so it will become six And then we are creating a memory block Jay So the six valuable big will get copied here and then if they print the value If I NJ So six and six will be out output. Okay, So currently, can we do like we have all ordered the plus operator for fraction class Go. So can we do this? Infection after is plus plus F one. Can you do this? Okay, so let's try to understand whether we can do this or not. So let's coming toward the scored. So what? I want this affection F three, which is less plus F one. Okay, so can we do this? And after doing a friend or bent, let's also print after. Okay, so now let's in this file. So we're getting an error, this lane, and that is Let's see that it. So that is the return type of the function operator. Plus plus is void and on the left, inside the everything affection. Okay, so this is wrong. So if you can see the return type of the function operator plus places void and what I would drink do it is dysfunction is in order. Dunning anything and in the left hand side of the everything object off type affection. Okay, so you stayed this world through us at it. Okay, So what I want to do is I want to make this thing bug. Okay, So what will happen? I will write gold in such a way that first F one will get depleted and then the value of F one will get corporate into F three. Okay, So what we want is so when we right into J is blessed place, I So if I was initially five. So this is I and it contains the value five. So what will happen first? I will get a blade so it will become six. Then a memory block. Jay will be created and then the value six will get copied. Okay, so I will do the same. First, I will abate the fraction F one. So the fraction F one if it was initially 10 and denominator was too. So first, the fraction F one will get updated so it will become six by one. And then we will copy the value into affection F three. Okay, So the return type of the plus plus operator plus will function has to be a fraction. Okay, so let's see. So initially, with heart returned, I will be void. But now we know that it doesn't. I will be affection. Okay. Certain type restriction. No, after a breeding the current flexion. We have to return distraction. So return this No would have done this. Is this laying correct? Should return this or should return something else. So let's see. So if you look carefully when I ride into J is plus plus I So what? I'm returning. So the value of five initially was five now would become six. So I am returning six. I'm returning the content. Okay, now let's say the fraction F one the fraction F one has memory address 7 700 So this contains the operator plus Plus this contains address 700 and the new tender denominator gets updated. Initially, it was trained by two. So now it's become six by one. Okay, so I have what I'm doing here is I am returning This This contains the address. This contains 700. But we do not have to return 700. We have to return the content. We have to return the content. Okay, So filtering the content What we will do we will return. Start this. Okay, we have to write return. Start this because we have to return the content. Okay, so we have to write start this because we want to return the content. Okay, so let's in this file and now I'd live. There should be no other at this lane. Okay? So I'm printing the well off F one and F three. Both will be same. Okay, so let us try to run our gold so we can see initially the value off fraction Afghanistan by do then we are printing the value off F one after doing, plus Persephone. And this is the value affection after. Okay, So our court is working Fine. Okay, so now let us try to analyze one more thing. So now we will analyse one more thing. Okay. So what happened is when I write anti now if I do bless place bless, bless a And if I tried to print the value If I let's say the initially initially the value if I was five, then see out a brittle you output. So output will be seven by seven. Because at this line I will get the memory block. I This contains the value five then first this operator will get work. This operator will work so it becomes six. Then again, plus plus. So it becomes seven. So our produce seven Okay, so can we do that? Same thing or infection? So what I want to do is build ist court work, plus press plus plus f one. So will it work? So first plus plus will work on F one. And we know dysfunction, returns, affection, the slowdown, affection. And then this place place will work on destruction. So I delete it should work. Okay, I lied. Should work. So let us try whether it revoke or not. Okay, so let's commend out everything. So what we want is we won't mess turd. So we are doing. We are using nested operators. We're doing nesting here, so plus plus plus for assessment. So will it work? So after doing this letters tried to print the value of F one and let's see whether it will work or not. So we're friend, art friend. Okay. And before doing this nesting thing, we also print the value of her friends. So therefore not print. Okay, So what should be on output? So initially, the new military under denominator contains stand by two. So this is my fraction f one. So first I will do plus process often, so it will become well by two. Then simplify function will get cold. So it becomes six by one. Then we are again calling plus plus on six by one. So six by one. Blessed one. So output should be seven by one. Okay, so this is the expected output. This is expected output. So let's see what the lower output. So our port is coming out to be six by one. Okay, so this nesting thing is not working. Our produce still coming out to be 67. We arrest expected output was seven by one. That means there is some problem in our understanding. Okay, so there is something which is going wrong. Okay. So far before analysing it. What went wrong? Let us try to move one more thing. Okay, So what we will do? Let's try to write it in this fashion. So fraction of tree is bless place plus plus F one. Okay. And now let us spend the value off a final FTS ofon dart, Brent and after dark maned. Okay. So over. It should be on output. So as we see this value, if we're diet will try to print this value it was coming out to be six by one. So ideally, what will happen? Both will be six by one defendant of three boats will be six by one. Okay, so what will happen? Actually F one will be six by one. And after he will become seven by one. Okay, so these two values will be different if one is 651 after is seven by one. Let's see. See, I told you on F one is 67 after you seven by one. Okay, so why? This is weird. So why this weird behaviour is coming out. So let us try to understand what happens. Okay, So what happened is when we write and I has five. So what will happen? First of all, there is a system befor days are temporary memory. This is a temporary memory system before it will contain the value five. Okay, Then we will get memory located two very ballet. Okay then very well. I will be created and this five value will be copied. And then this five failure will be corporate and then this memory will get diluted. Okay, So this is how it works. Let us try to understand a bit more So I suppose I have a function. Let's see, I ever function and fun. This function takes on teacher variable as input. Then it will the Y plus plus and then it is returning. I okay, and let's say this is our main program and we're calling the function from here. So we are doing and G and we are calling the function I and let's say the value if I is five and then we are trying to print the value of G so Howard will work. So when we call the function fun five So what will happen? This I will contain five. Okay, so this I contains five. Then we do I plus plus So it will become six and then we are returning. I Okay, so when we return, what will happen? So when we come here, what will happen? Our system memory again Ah before will be created that before well contained the value six Ok, similarly like this What will happen? A system before a system before which is a temporary memory will be created and it contains the value six And then what will happen into G so a box G A variable. Gee, the variable Jay's A located memory. And then the value six will get copied here and then the value six will get cooperate here and then it will see LG then six to live printer. Okay, so this system, before this temporary memory is created by the computer. Okay, so we are not doing anything. This is created by the compiler. We can say the system. Okay, So what will happen instead off writing this line? If I try to die clip print if I will call the function using this using this lane what we happen. So what will happen? This function we really reach here again. I will contain five. So then it will become six and then we are returning I So when we're returning the value, what will happen again? We will get a system before the system before Let's call it X. So the system of first contained the value six. And now here we are not receiving it. Ok, now we're nor deceiving it. So what's the out will do? It will go to the system before and it will print this value So six we've got printed Okay , So see out Will goto system before and it will read its value, and it will print it value. So this way six will get printed. Okay, so we are not receiving anything here. We're noticing anything. We are directly printing. Okay, So for directly printing words, the out will do, it will reach the system before it will reach the temporary memory. And then it will print its value. Okay, So now alertness see the same thing which is happening here. Okay, So how this little book? What is the editor here and how we can correct this error? So what is happening here is So let's say our new military is 10 and there'd be no minute. That is to So this is our fraction f one. And let's say the address is 700 and this is 700 so we are calling. So what we are doing here is we are writing something like this. So friction f three is bless place. Bless place F one. Okay, so first off, all we will operate on firstplus place. So what will happen? We will reach the function operator plus place. So when we reached the function operator plus Plus, this will contain address 700 and then the value off numerator will get updated so numerator will become Ah, six send their do, no matter will become one. So this is after the simplify function. So this is after the simplified function and then if you see the court of the other turning distraction So this is currently at the 700 we are returning destruction. And I told you when we returned the fraction but will happen, it will go into the system before. Okay, so we are returning a fraction. But we are not receiving it. So we are returning affection. I will reach demean. Then what will happen? A system before will be created. It contains new monitor is six and millimeters when So when we reach the mean So the output off. This is this one. So when we reach the mean this is ours temporary memory or we can say the system before Let's call it X. And let's say it's address is 800. Okay, then what we are doing here is bless place. Since this function is returning something, but we're not receiving it. So what? This place place real. Ooh, it will operate on this instead of operating one. This one my plus plus will operate on this on the temporary memory. So what it will do now this time might this will contain address 800 again the numerator will become new metal plus denominators on numerous turn denominator will get updated so it will become seven and it will become when after this MP five function. Okay, so this is after the simplify function and then we will return distraction So we will return this fraction too mean And when we are returning, what will happen first? Awful. A system memory or temporary memory will be created so that temporary memory contains numerator is seven and the dormitories one. Let's say the name of this temporary memories. Why? And let sales addresses 900. Okay, so after this, what will happen a fraction after he will be created a fraction after he will be a located memory human attended Amrita And then this value will get copied. So numerator contains seven. And the tournament the contents one. So when we do f one dot print, what will happen? And when we do after dot print So when we do a friend or print So this is our F one. So it contains six by one and this is our F three. So it contains seven by Evan. Ok, so that is how internally this is working. Okay, so that is how internally this is working. So how can we like how can you correct this method? Okay, so what is happening here is the main problem is this thing. This place plus is getting operated on this system memory this pem bready memory. Okay. And we want this plus plus short book on this address 700 only. Okay, so we want this memory. This temporary memory should not be created. We want this temporary memory should not be created. Okay, Let us try to understand a bit more. So what is happening? It is initially the value of new military is 10 and the tournament is too. So we are doing bless place, bless plus F one. So first of all, this plus plus will work on this one and its value will become six maven. Okay, then what will happen are temporary memory. When we return, the fraction are temporary. Memory will be created a system before will be created. So when we right and have done started this And when we reach the main program, a system memory will be created. Let states led to the name is X and it contains the adversity it 100. So this time this place places working on this one. And we want this place. Pleasure work here only. Okay, so what we can do is we will write code in such a way that this copy is not created. So if this cop is not catered, what will happen? My system mot my system before Well, point here only. Okay, So can't leave in the memories created the system before points here. But if the system before isn't articulated, the copy is not created in the system before. Well, point here only. Okay, so before will point hair only. And then this plus plus will work on again work on this, and then this really will become seven by one. Okay, so what we want we want copy should not be created. Copy should not be there. Okay. So whenever we want that cooperation or vacated what we do, there's something called reference. So we know fast benefits we estimated about bass. By defense, there is also which something. There's also which is called returned by reference. Okay, so we know what this past biodefense days, something called Returned by defense. So references used whenever we don't want to create a copy, so we will return the friction by reference. So when we're done, the friction by difference the copy will not be created. Okay, so the copy will not be created. So let's even more time when we passed by value. So when we pass when we passed by griffins, what happened is let's say this is function it contains and I and they're done. Type is in teacher. So there's some cold here and let's say I'm calling from the mean and let's say this is I have entered Jay's one and I am passenger. So what will happen? This is by reference, so I n g both are same. The boat contains one, so new copy will not be created. Okay, J points towards this, and I also points toward this so we never really done by reference. If he will return by difference, then when we will reach the mean at them very memory will not be created. Okay, so they're temporary. Memory will point towards the memory, which is inside dysfunction. Okay, so we have to pass by it. Offense here. What we have to do, we have to pass by reference. Okay, So now let's end this fight. And now when will run this file? A friend of the F three Both will contain the value seven weapon. So see, this time both contains the value seven by one. So now our court is working. Okay, so let us try to understand one last time. So we are doing plus plus bless place F one. Okay, so let's say that address off if one is 700. So numerator and denominator. So there does is 700 the values stand by two. So this will contain So it ended. So it will become to a burrito. After calling the simplify function, it re become six by one. Then we are returning by reference. Since we are returning by reference the system before three point the words here, it will not create a separate memory system before I will point towards this only. Okay, then we are agreeing. Calling plus plus. So this time, this place Phyllis will get golden system before, so this place place will get cold on system. But for now, system before this point him towards this. So ultimately, this place press will be called on this only. So now the value will become So this contains this again convinced 700. Now, that really was 6.1. Okay, so this is 700. So this contains 700. Now it will become seven by one after calling after addition and calling the simplify function. Then we will. Then we will return by reference, since we are returning by reference. So the system before will point towards this. And then this really will get corporate into affection. F three. Okay, so F three and F one both contains the same value. Okay, so the involved plus plus the inbuilt plus plus the pre inclement operator works like this only. Okay, when Brett operator works like this only so initially what was happening but was our mistake, So displace place. We know this place dress will work on the system before this is for sure for initially earlier. What was happening? The system before was point them towards a copy are temporary memory ritual, which was containing the value six by one. But this time it's air dust was different. Let's say 800. So our earlier the system off was pointing towards a copy, Okay. And the plus plus was working on system before and system before voice pointing towards this. So that's why this value will you come seven by one. And this will level get corporate into F three and F one remains six by one. Now, what we did is we passed by defense. So this copy is not created. And the system before WellPoint the words six by one only at just 700 only and plus first will work on this 700. Okay, so that's how this work. Okay, so then built increment. Operator works like this. Only interference by a difference. Okay, So in this way, we can do as many levels off nesting as we want, and it will look properly. Okay, Now the last thing can we make this function a constant function? So what is the definition of a constant function? Ah, constant function is the one which will large ease the properties of the current object, since it is changing the numerator, so dysfunction does not qualify for a constant function. Okay, so in this video, be overloaded. A pre increment operator, and like, this was a little bit complicated. Okay, So what about the complication is always fine. So I hope you understood this radio. Okay. Thank you. 19. Operator Overloading 3: Hello, everyone. So in the last radio we discussed over lording being Clement Operator. I hope that is clear in this. Really? We will try it, Overlord. A few more operators. Okay, so let's start with the plus Plus operator. So let's start with the post incremental breeder. Okay, so in this video, we will try to or Lord posting grand operator. Ok, so this is a unity operator. OK, so how we will call friction if one blessed place Ok, since this is a unity operator, so f one will go in this and there's no need to pass any argument. OK, so first let us try toe first let us revise their difference within the pre and the post increment. Okay, So free and post So their defenses see if I write and I is five and I bless flys And if I tried to print the value off, so did this is be so bless. Plus I And if I tried to print the value if I sold output will basics okay? And similarly if I do post increment And if I tried to print the value if I then on several basics so here that there is no difference. The difference Will you come Venerable assigned the values. OK, sir. Difference between post Temple Incremental Come when we will assign the values. So let us assign the values So mpg, this is blessed. Bless I. And now let us try to print the value off I n g. Similarly, I place press and Brenda really off i n g So the value if I will be six and the value of J will also basics in this case, the value off I will be six, but the value of J will be five. Okay, so what happened is the increments is first increment and then use. Okay, So that's why a 676 various post increment will say first assign first to use and then inclement. Okay, So the difference will come when we will assign the values. OK, now how we will differentiate in diffraction class. Okay, So what will happen? Infection class? How we will call the function. So we will write something like fiction. A four is everyone bless bliss. So let the says you the initial value off, if one is so numerous turned to nominate Tory's that certain by toe So this is initially a friend. So post increment will say first a sign and then increments. So the value off a four will be the same as the valley off F one. So 10 and do so. This will be our before and for F one, what will happen? We will do Plus one. And then we look all simplifying, so it will become six by one. Okay, so this will be the value off F one. Okay, so let us overlord the function post increment. Let us Oh, Lord. Operator post increment. Okay, so what they will do We have to return affection and perfection. We have to return the old value. So this is the old value and this is Denny new value. Okay, so now let's in cold. So it's time to overlord boasting agreement. Okay, So first off, all but with the return type written type cannot be void because we have to return type cannot avoid because we can also assign values. OK, so that's very turned type cannot avoid Went I will be affection only, and then nobody did. And then operator, which we want to overlord so it will not take any argument way because it's a unity operator. Now, see, the name of the function is exactly the same. Corporate surplus and operator Plus So how to differentiate between the P and the post increment? So what we will do? We will write in visual here. Okay? So, no, this is posting agreement and the above anus increment. Okay, so you have to remember this that we have to pass in Piedras argument. Okay, so what we have to do? First of all, we have to return affection and the friction with the old values. OK, so friction with the old values. So fraction f knew it will contain the numerator and they're denominator. And now if you have to do first, first use and then increments No, we will increments. So numerator will become numerator. Polis, denominator and the inimitable remain unchanged than what we have to do. We have to call simplify function, so simplify so implicitly it will be called on this side of simplify. Okay, now we have to return defection so Britain start. Sorry, we have to return the old affection so f new. Okay, so what will happen? So this is F one numerous. 10 denominator. Value is standing toe and lead suits produces 700. Okay, so this will contain 700. So I'm creating a new fraction f new. So we have a new fraction. Numerous distant during night raids to this is F new. Okay, and let's say it's address is 800. So new militaries numerator place, no matter. So whose numerator? This acronym editor. So 700 new monitors. So it will become well, and this will remain s true. Then we are calling the simplified function. So simply five will make it six by one. Okay. And then we had a dining f new. So then we will return this one. Okay, so let's do one more thing like that's also simplify distraction so it really become five by one. Okay, so it does call simplify function on f new. So if new, not simplify. Okay, now they're discreet Affection of three. So let us create affection f three and we will use post increment. We will call Boston criminal. Okay, so f one plus plus, And now we will bring a finally after so f three not burned. Okay, So what should be on output? Okay, So since we are calling post incremental. First F one will be assigned two F three so the value of 50 will be five by one. Because we are also calling simplify function and then everyone will be implemented. So the value of F one will be six by one. So that output will be 651 and five Weapon. Okay, so let's see. So that would produce six by one and 5 11 Okay, so our record is working now let's even mooting now if I arrived and day is five and I place place and bless bliss. And if I'd tried to print the valley off I so virtually our output. So what I'm doing here is we are doing nesting nesting one post increment, so it will throw a center. Okay, so nesting is not defined for it. Forced increment. Okay, so nesting is not allowed for post increment. So since nesting is not allowed so since nesting is not allowed for posting agreement, so we will not do. Okay, so there is no need for us to do nesting. Okay? So if you will rent the score, this will through a center similarly of accord will give us unexpected output. Okay, so very strange behavior will be observed. Okay, so now let's stop. Let's stop posting agreement here. Now let us try to overlord when more operator which is called Blessed Collaborator. So now we will try to overload Blessed collaborator. Okay, so we're displacing coal operators. So when I write and a faith and jays, let's itri So if I do, I bless equals g. So this is basically the short form off writing. Eichel's my pleasure. Okay, So what will happen? The value off I is initially Fife and the Valley off J is initially tree. So after this line, it will become it. Okay, So add the two values and put the resulting I. Okay, so for classical operator, nesting is defined. Okay, So if I write, I place it Quill j. And then if I do the nesting place ecology, so output will become so this will return. This will make the value if I is it. And then we're doing classical studios, so this will become 11 and it will remain tree. Okay, So the value if I will become 11 and the Valley of David Elementary. Okay, so this operator has nesting properties. Okay, so nesting is allowed, so let's see. Let's try to experiment first. So what I'm doing? And I is five and into jails three. Now I Pless equals J similarly classic ALS J. Now, if I tried toe print the value off I NJ so that would put will be 11 anti, I guess it out. Put this 11 and so output is 11 entry. Okay, so nesting is defined. So that means we have to also keep this in mind. Vital lording the operator. Okay, so how we will call our function. So what we call something like this Fraction F one classical fraction after, since it is a binary operator. So the F one will go in this and after will be passed as argument. Okay, so this implements F one is f one bless f toe. Okay, So we are riding two factions and put the result infection. When? Okay, So if you see, we have oil a day than dysfunction. If you remember, the air functions So the function led off. It was something like this only. Okay, so now let us see in court. Okay, So, first rifle, but we returned. Type so the return type will be a fraction. Very turning a fraction. And since the nesting is allowed, we will return by reference. Okay, We have to return a fraction by reference via by reference, because the nesting is allowed. Okay, so let's see. Okay, so let's see. So, first of all, where the return types to return type will be a fraction. Okay, So my affection, because we need to return affectionate, cannot be avoid, and then operator keyword and the operator which you want to overload classical. So what? But it will take It will take a fraction as input and fiction if to Now we know about constant references. So we will pass constant refrain because you do not want to call Copy Constructor. And also, we want to avoid any legal changes. Okay, so the functionality will be same as add function. So there is a road function. Okay, so this is our function, so we'll go with discord. Okay, So what we have to do here is we have to make the changes in f one only. Okay, So oncoming discord. And we do not need this cord. Okay. Okay. So when's the numerator and the denominator is updated. We have to call the simplify function. So after calling the simplify function, we also have to We're done. So didn't start this. Okay, now let's see now, ladies first, take two factions sensi but will be out output. So? So let's say I have two fractions. Have fun. And after So for reference, the values off numeric earned elementaries. Let's say 10 entry. So this is fraction F one and four fraction after. Let's say the values are five friend too. So this is friction after address. 800 address 700. Okay, so when Villard this to fiction but will be our output. So our output will be a simple basics. This is 20 plus 15 and this is turned to five by six. So after calling the simplify function, output will be certified by six only. Okay, so this is our output now how we will call this function. We will call the function F one plus equals f two. Okay, so after will remain and changed. So the value of have to will remain same as five by two. And F one will become 35 by six. Okay, so we are doing. We are calculating the else him. And then we are a breeding, the numerator and the denominator off this. And this contains 700 basically f one. Okay, then we're calling the simplify function, and then we are returning f one. Okay, so let's see. So how will called affections? F one place equals after. So first of all, that has changed the values off a friend after as we have discussed. So the value of F one waas then by three and the really off afterwards, five by 25 and do Okay, so our output will be 35 by six. Now, let us try to print the value off A friend of tools were friend or print and similarly afterthought print. So the value of have to will remain unchanged and the value off F one, it will become 25 by six. Okay, so the value of 15 became 35 by six. And that really offto is five by two. Okay, so have a cord is working. Fine. Okay, So one more thing, I hope you understand driving you to pass by reference. Returned by reference. Okay. Vie written by difference. Because if you were right if you were right. Like if one place equals f toe and then again place equals have to if you will do nesting so they feel not returned by reference than thou put off this thing will be a system before a system, a temporary memory, and this second place it questo will work on that system memory. Okay, so that will be wrong. OK, we do not want her to work on system copy. So that's why we have to return by reference. Okay, So if you want to condemn this file, let's Okay, so now that it's in this file, so after remains unchanged in the value of her friend s 25 by three, which I'm assuming is correct. OK, so arriving here to return by reference. So if you will not written by reference doubt put off this part, it will be a system copy. It will be a system copy. And this second place equals to this will work on the system copy, which we do not want. Okay, so that's why we have to return by reference. Okay, So I think we have all ordered almost all the important operators. So if you have any doubt, feel free to ask. Okay. Thank you. 20. Dynamic Array Class: Hello, everyone. So in the last session, we learned about operator overloading, and we always ordered many operators for our fraction class. No, we want to create a class from Dynamic Gary. So indecision what we will do. We will create a class dynamic, Carrie. And in the Democratic last but other functionalities. So we want first off what? We will take a India ready and the function that we want is user can add as much number of elements as he wants. Okay, So the problem with the normal arrays we have to tell the size in front. Okay, We have to tell the size before and declare diarrhea off size five, the size will be five. The size can be 10 or the size will be n Okay. We cannot extend the size Laurent, for example, if we have an area of size 10 so if we have an area of size 10 So this is indexed nine. We have an idea of sistan so we cannot insert the 11th element. User cannot insert the 11th element of the size of their eastern. So we will solve this problem by building our own class. Okay, so what we will do. How can we solve this problem? So our logic is internally. What we will do so internally we will maintain in every Let's say, the size of that is initially five So 012 three and four. So let's say it initially the size of their raise. Five. So what we will do as soon as the user will enter the sixth Element Essen is they use Ever tried to enter the sex element. But we will do. We will make a new Eri so this area will be doubly so. The size was initially five. Now we will create an area offsite stand and we will copulate up. For example, a date of Western 40 30 40 and 50. So we'll create a new area. Were you copy the data certain? 20 30 40 and 50. And now the user can insert the sixth element here. Okay, So you was everyone. Insert this ext element here and now this area This will point towards this. Okay? And we will deal. Locate the memory SNS. Our area gets filled up, but we will do We will create a new Eri copy day content from the old Ari they locate the old area and now the arrival point towards this. Similarly, if this a rebel girl field if the size if all the 10 elements are in the area but we will do it will create an area of size 20 will copy the older 10 data fields, all 10 data and then the new arrival point towards this area off size 20. Okay, so in this way, we can solve this problem. OK, so what will be our data members? So what did your data members, first of all, we will need our dynamic. Ready. Okay, so in started now. So this is over in p. Jerry and Pieter Pointer so initialized decided dynamically in the constructor. So in the constructor. But we will do in the construct. We will initialize this dynamically. Let's say initially, I am taking the size to be five. So new and Fife. Okay, So this is how we will initialize Dari. So what will happen? This is data and it is all size five inside the constructor. Okay, So what we will do now? We will want a function. So we will have created a function. Add element. So what? This ad element function will do. It will take our element, which is to be inserted inside the area. So weird element will be inserted so the element will be inserted at the It will be inserted the next index available, for example. Let's say the sad A contestant and 20 So the element will be inserted here. Okay, so let's say that limit is 30 and next element will be in started here. Similarly, the next element will be inserted here. Okay, So next. So there are elements will be inserted that the next index available. So inside this function, what we will do We really so details the name of the Eddie data and element. If it is the first element, so it will be zero every the second element. Then it will be one and so on. Okay, so how can we know that at Richard? Next? We have to insult. Okay, So how we can decided to return next? We have to insert element. So for maintaining this index, we will create one more data member with the name next to mix. So I will have one more day, remember? And next UNIX. So next index points toward that index, which is empty, and we can assert data there. Okay, so initially, next index will be zero. We will insert our first element at index zero. Okay, so what we will do, we will, Right? Dared off. Next index is element. And then we will soon, Next to next, plus plus. Okay, so this is how it will work, okay? And no, we will also take one more. Did remember which is the size of the area. Okay, so these that's idiot remembers that we will take Okay, Let's take an example to understand it's better. So let us take an example. So let's see. Initially, my dear dies off size Fife and initial either at ASEM Pretty buy em pretty. I mean, it contains garbage value. Okay, so 0123 and four maximum texel before And I am having next to index and size. So these other theatre members, initially next index will be zero and the sizes five. Ok, we will call the function, add them. Okay, so 10 will be inserted here and the next next becomes one. Then you will call our 20 so 20 will be inserted next next to inserting Add 30 thought are they will be inserted now. There next becomes three air 40. So this is add function now air 40. So far they will be inserted in next three and now they next becomes four. So now add 50 so 50 will re inserted. And now what will happen if I try to insert one more element? So if I write, add 60. Sorry, this is the next becomes five. So when we write, add 60 s So there is not space to insert element. And what happens next? Index become equal to the size. So as soon as the next Next in the size, both are equal, but they have to do. We will create our area off size and w So this area was off size for now. We will create an area off size 10 and we will copy. The five feels the five data feels so 10 2030 40 and 50. And now the 60 will be in started here. Okay. And so the next index will become six and the size will get abated to 10. Okay, so what? We have to remember we have to remember if the next UNIX becomes equal to size. What you have to do, We have to double Larry. We have to create a new area off double size on copy the old content. Okay, so now let's see in cold. We really listing with the help of court? No. So I have a class dynamic, Harry. So what I will do? I will keep all my properties private. So let's create our data. Let's clear diarrhea with the name Gator and we will keep next index next nexus, then decks at which our element will be inserted. Initially, it will be zero and capacity and capacity is the total size of the area daughter size off the Eddie. Okay, so now let us create a constructor so public. So in the name of the construct plays we along with the same as the name of the class, so dynamic. And now we really initialize our data members. So first initialize our dynamically so their ties its own Pizzarelli. And let's say initially, I'm keeping There are size of that had to be five. Okay, so we're next to index. It will be zero because the first element will be in severe zero and I'm keeping the capacity, the total self that it will be five. Ok, now let us create a function. Our function so avoid aired. It will take our element as in board, which is to be inserted. So element we have to insert this element inside our area. So we have to handle the case when the next size. So even the next index becomes equal to the capacity of the area. Now, if this is not the case, then the court is very simple. We just have to go to the next index and then for the element. Okay? And what we have to do next, Next, plus Plus. Okay, so now let's see. Now, let's see, how can we handle this case when the next index becomes a call to the capacity? Okay, so how can we handle this? What we have to do. Okay, so now this is the case. Whenever ari gets filled, so next size. Sorry. Next index contains five capacity contains five, and this is a very so five elements have already been inserted in this area. And then 20 30 40 and 50. Okay, so this is my dear diary. Okay, So now what I want, where I want to add a new element at 60. Okay, so the next index equals to the capacity. So what I have to do, I will create a new area off the bed size. So this is a new Eddie of the well size. So zero when toe three. Four and it will go upto nine in next nine. Okay, so after creating the new area, let's name it new data. So this is new data, but we have to do We'll copy the old content. You have to copy the old content. So 10 20 30 40 and 50. So, after copying the oil content, what we will do so we will delicate this memory. So since answered, I nick memory, we have to since this memory decided, skated in the heat memory, we have total it'd OK, so it is our responsibility. So we're delayed this memory and this data well now points towards this area, and now we will air the element here. So 60 will be added here and the value of capacities now 10 and the next index will become six. Okay, So in this very playbook, I guess so. Let's ride the court for this. What we have to do we have to create a new area off double size. So let's neighbor new data. The size will be double so new and two times of the current capacity. Okay, so after creating the new area, what we have to do copy the old content. So for copping the oil content. So I lived in capacity. I place place so new Delphi is you're Delphi. So the second mark is also done. We have cooperator, but we have to do we have to delete the old lady. The area which was initially offsides five. Okay, so we have to delete dietary because it's our dinette memory. Okay, we have to related It's a heap memory. So we have to delete the world later. And now the old data. It will point towards the new later. The newly created very and we have to double our capacities of capacity will also get a bitter So capacity quiz capacity multiplied by two. Okay, so what will happen? So we are dilating the data. So what will happen? It will not be let the date on. It is called memory leak. I think I have already told you before. What is memory leak? So the data was pointing towards an area with was Offsides five. And then we created a new data. So this new data, this was Eddie off size 10. So what I did, I'd littered this memory. And then the new data points toward the detailed old data point towards the new theatre. Okay, So if you're not delighted this memory, then this phenomenon is called memory leak again. It has quite a memory leak. Or guess over more thing by the details. Point him towards this new data. Why? Because if you see here the new data, the scope off, new data, it is inside the if block only a guess as soon as you will reach line number 22. The new data is not like it will not exist anymore. So we have to leg point so that their travel point towards the newly created data New liquor to Daddy. Okay, So what will happen? The capacity will become twice Now. We will come out of the if condition and then we really insert the element. So if you want to insert element 60 so element will be inserted and we will do next index plus plus. Okay, so this was very simple. Now let us create one more function. So this function is get element function. Okay, so get element function, but it will take it will take. I indexes input, So use every. So you several ask us what is their data present at index too after next three. Okay, so we are creating a get function. So inside the good function. So if then Becks is valued by valued. But I means so if they indexes garden or close to zero, obviously index cannot be negative. So if then Dex is valued indexes north negative. And also the index is less than the next index. Next next means the number off inside dairy. So if the index is less than extra next, then Italy weekender tender data. OK, so return date off. I now else what value? So in the else part, that means the index is not valued. Okay, so we will return. We will return our default value. Let's say their default values minus one. Okay, so if the index is not valued, let's say the index's minus two so minus two like it means nothing. Okay, so we will return minus one, and similarly, but there's an extra next. Next next is the number of elements that has been inserted inside the area. So let's say than next. Next, Ray Lewis five, and I ease. Let's a 10. So obviously we will return minus one. Okay, so what I'm saying here is So let's say I created object offer dynamic arrays or dynamic every day. Even I am creating an object. So next index is the initially capacities. Fife initially. And the data contains the address 700 and this is our very off size five. So that doesn't the first element. This 700. Okay, so zero when do and extreme and index food. Okay, Now let us straight. Where the elements. Okay, so, ed 100 at 10. So 10 will be inserted. Next index becomes one at 20. So 20 inserted. Next. Next becomes too at 30. So tart inserted. Next. Next becomes three. Air 40. So 40 inserted. Next UNIX becomes food aid 50. So 50 inserted. Next. Next becomes Fife. Okay, So now if you will add 60. So what happened is next index and the capacity they become equal again. Very simple process created. New Eri Now the size of this area will be the old law It will be 10 So the capacity God separated to 10 copy the world content So then 20 30 40 50 So next index will become six and Belem in 60 will be inserted. And let's say the address off this new ties a tender. So this is new data there does off new their ties to tender, So this data will get a beauty to 800. Okay, now let's see the get function. So he said the good function If I write, get three So index tree is a positive index and also the index tree is less than six, which is next to index. So that means index trees valid. Okay, so in Dexter is rendered. If I write, get six. This is not valid because because the value of next indexes six. That means that next element which is to be inserted it will get inserted at the next six. It is empathy. So this is wrong. That's why every right this condition similarly fire right get 50. So obviously this is also wrong because we only have currently are six elements. Okay, so this condition, it is very important to write this condition. Okay, Now let us create one more function, which is the variation off this air function. Okay, So what we will do? No. This time we want to add an element so avoided, but we want to add an element. But this time, use ever give us that index at which given stored element. So anti. So the meaning of this line is insert the Element Art index. I OK, so we have to insert the element. And after next I let's take an example. So that same idea diaries Let's say it is, then don t 30. And so my arrays of size 50123 and food. Okay, Next indexes three. And the capacity is Fife. Okay, Next nexus. Three capacity is five. Now let's see dysfunction. So the element is let's say, 100. And he was everyone's to insert at the next to So we'll go to index to Metis 30. We will make it 100. No problem. Okay, this is right in next to element 100. It is right now. Let's say the element is 200 they in Texas three. So I use three, which is equal to the next index. So what will do? We will insert. No wonder there No problem. Okay, Now let's say the element is 300 let's say the indexes then. Okay, so indexed in so index turn does not exist. Okay, so if you compare so index 10 is greater than next index. So if this is the condition, that means this is wrong. OK, so this is right. If what is the condition? So I is less than next to index. And this is the condition when I equals two. Next. Next. So these two conditions are valid and this is not valid. Okay, so in this case, we will not do anything. We will not insert element. We will simply return. Okay. In this case, we will seem better. Done. So the first case when the element Tobin circulate and Xie is less than extra necks then it is very easy. We just have to override the value. Okay, we will just have to move right. The current value element? No, the second case waas when the index at least element obeys inserted. Is it close to the next index? So in this case, what we have to do, we have to handle everything. Like if the area gets well, we have to double the size copied or Larry, copy the content of the whole area and everything. But for that we will recreate the function ad. Okay, so we'll simply call the ad function. Okay, So for this case, when the element to be inserted is next index. So we simply really call dysfunction ad So this air function will get called and the search function will handle everything. Okay. And And it's when we come to else when the when index I is guarded and in extra next. So in this case, we will not insert the element. We will simply return. Okay, You can write a prince statement, or that is the index is not valued or something like that. Or you can throw other OK, so you can do whatever you want. I'm simply returning. Okay, so now let us also create a print function, okay? So that we can print our ready. So what? It does create a function wide print. So what this friend function will do it, will. It will bring the elements of the area. Okay. So far, we just have Dwight rate Nothing much so far. And I quote zero I less than next index. I bless press and we will Brent the really off the the content of the area. Okay, okay. So dead soul. So one thing here is I listed next index. This is right, or I should right, I listen capacity. So I we should write I listed next to index by next. Next. Because next index means these were a number of elements has been in surgery inside the area. Okay, capacity, music. Total size of the area. So we have to right next to index. Okay, so now lettuce, Right to create some objects. And let's see how our court is working. So we have included the file dynamic, adored see pp and the name of this violist dynamical reused, or CPB. Okay, so that does create object. So dynamic Adi Divan. And let us add some elements. So then So we are inserting six elements. Okay, So I had this land What will happen? The four constructively, but called the fall constructor that we have Ah returned that we have created so that constructively be called. So the size of January was five. But here I am inserting six elements. Okay, So what will happen? The size of diaries, then the size of the area is 10. And because the new edible be created. Okay, so now let us call the function print. Also, let us create a function, get capacity so that I can prove it to you know that the size of their ace 10. Okay, so get capacity function. So let's say I have a function returned. I will be in teacher. And the name of the function is get capacity. So what? It will do it with redundant capacity of the Danny McKenna is we're done capacity. Okay, So the size of the Arab was initially five. And then Vince, we insert six elements. So the size will be then. Okay, so we're here. We can see the size of the size will be then. Okay, So now let's win this file. Okay. So what we have to do? Oh, what is the problem? Sam, You go. Oh, and also Okay. So Okay, we have not been entered, so let's sprint. The capacity. So she yelled Different target capacity and lane. Okay, So the content of their is 10 2030 40 50 and 60. And the size of the arrays then. Okay, so have Accord is working. Fine. Okay, so now let us create another object. So dynamic area Butto given. So what will happen at this line? We all know copy concert people be called, since we have not it on the copy constructors. So what will happen in bed? Copy? Constructor will get cold. And now let us change the valley off. But I am doing I'm inserting the Element 100 average index zero. Okay, so let me see first. So first I'm taking element and then index. So I have to give element first. And then I am giving the index. Okay, so now that the sprint divan and we will bring do you do so what will happen? So at this land, what will happen? Copy custom People be called and we all know copy Constructive. But it does. It creates shell a copy. Okay, So what should be our board? Let's see first. So let's see of indicated vendor default construct place called. What is the scenario. Let's say we have inserted only four elements. Okay, There are only four elements we have inserted for elements. So, divan data, Let's say it contains the address 700 and the next index, it will be we have inserted for elements. So next, next, Well before and its capacity is five. Okay. And at this land, we are creating a new object. So do too. So, due to data, we'll also contains 700. It will copy all the properties of the divan object. So the next index also four. And the capacity? Well, it's a Fife. Okay, so we can see here. 707 100. So what copy? Constructive will do. It creates a shallow copy so shallow copy will be created. And what I'm doing here is I am changing the first value of their I'm changing the zero Telemann 200. Okay, so the arrivals 10 2030 40 50 and 60. So this was Diva Neri, and I'm changing the first index now doing very well become this 120 30 40 50 60 on. We're printing divinity to But we will see when I print due to our goal will be 100 at zero Index 100. Well, we've entered. Okay. Bye. Because we all know cop, because typically it shell a copy, so let's see. Okay, so we can see here weather changes with your changes. India dynamic added even. But the changes are also done for Dynamic carried you to OK. And the reason is we all know by the course copy concert speculates shell a copy. Okay, so one more thing, can we use copy assignment? Operator? Okay, so let's try to use copy assignment Operator. So I am creating Dan McGarity three. So default constructively. We called and then I'm using copy assignment Operator. So at this lane copy assignment operator called, Okay? And then I will do changes for divan. And then I am printing even to do. And let's say we are also printing the tree. Okay, so I am bending divan due to and ditty. So we're this lane, our the Ford constructive ill Because, okay, our default constructive will be called. And then I'm copping the values off divan into the tree. Or at this line, also, our call our default constructively. Because so I'm copping the values of dividend to 23. So do you think after doing changes in even the day will not be affected. So the point is copy assignment Operator also create. Sell a copy. Okay. It will also clear cello copy. So they want you to the tree they all will contain. Everything will get changed. Okay, I am doing changes in Deven. So what changes will get reflected in due to Because Shallow copy and the changes will also get affected in the three. Because again, Corpus entered Operator again creates shell a copy. Okay, so let's see. So we can see Here is your changes individually. But the changes got reflected for do 23. Okay, so here it is mandatory for us to create deep copy. Okay, so how to get deep? Copy. So we have to create a copy constructor first. So for west, what I'm doing here is I am creating my own copy constructor. Okay. I am creating my own copy cluster. So this in Texas, very family here. So dynamic Getty. And what it really we will take on dynamic Gary Constant reference. So constant reference by constant offense because you do not want to call, copy, construct otherwise infinite loop I hope you remember. So I have to copy everything. So let's first copy the next index the dart next to Nick's. So this idle capacity is the adored capacity. And this saddle, dear guys, the dart data. OK, so this lane, this is shallow. Copy. So this is the cord which is return inside the inbuilt copy constructor. Okay, so now we will create deep copy. So I hope everyone remember, what is the procedure for creating the deep copies of the procedure is very simple. Clear the new era. Copy the world values. So we have to create January. So let's say new. And so what of the size size will be the Lord capacity. Okay, here we do not need to do placement in case off string vineyard to do pleasant because you want to co op it and I'll correct also So here, no need to do plus one. And now we have to copy the content. Eso In case hosting, we have a function sting copy But in case often, teacher, if we do not have such functions So we have to copy the oil content of dairy so d dot I should write Do dot next index or did or capacity. So don serious next index. Why an extra digs? Because next next meets these may number of elements has been inserted inside the area. And what we have to do, we have to copy the contents of this door. Data Fi is leader they don't offer. Okay, so everything seems fine. Let me check this. Okay, so according to me, everything is fine. I'll give one more thing. This is optional. Okay, writing this is optional. Because do you Darden Extra Index and next and next, we can easily separate out. Okay. And constant difference. I hope you know. Okay, so everything seems finest later in this file, and now we will run this for you. Okay? So what will happen when we're in this file? If we do changes, and even so, due to will remain unaffected. Okay, so let's see. Okay, So 100 the valley off due to is spent only. Okay, So have a court is working. And now let us fix this problem. Also copy assignment, operator. So it is operator. So what we have to do? We have to overlord this operator, and we're started about operator overloading a lot. So what we have to do? We have to adjust. Our Lord equal operator s over Delivered a return type so they don't have will be void were not returning anything. And operator give erred. I won't. Oh Lord. Equal operator. But it will be a guy's argument. It will take our dynamic, Eddie. And how it will take it will take by constant reference on Let's say the name is D. Okay, So what is happening? It is. So what will The cold the court will be exactly the same. Okay, it will be exactly the same. The court, which was for copy constructor. Okay, Exactly. Same called. So inside the call operator inside the coop assignment Operator. It also creates the shell a copy, but we have to create the copy s o b all ordered the operator. Okay, so how it will call. So we are creating dynamic Eddie. Let's call it. Do you do? And then we are using copy. Senate operators are due to question even So this thing will go in this and it will. You passed this argument. Okay, So are going to me is here. Okay, then this so this. Okay? I hope you know everything. Okay, So now others in this file and now we will also in this file. So now we can see then. Okay, so the three is also not getting affected by doing changes. And even so now, divan, they're 23. They're independent. Okay? They can work properly, mellitus create one more constructor. So this time, let us create when parameters constructor. Okay, So dynamic. Carrie, Let's say the user wants to give the value of capacity. Okay, so let's say use every give the value of capacity the initial size of the area. So do you guys. I will create the area off size. See? So the next index, it will be simply zero, and the capacity will be See? Okay, so now let us. So now what happened is use again. Great, Eddie off the size he wants initially. Let's see, initially, he wants a day off sites 100 so we'll be able to create a day off size 100 by using parameters, constructors or before daughter get capacity. Okay. And here of what we have Fatima Trays. Constructors. Our perimeter guys. Constructive. There's no need to write our because default that on my desk Constructor does not exist. So this is better. My taste Constructive. When we will do before, Don't get capacity. Our are our output will be 100. Okay, Okay. So I think we forgot to run this file. Oh, against animistic before got to print. So now we can so now diary. So now the size of the D four objectives 100. Okay, the size of dairies 100. So in this way, use again. If you want, he can give the size of the area initially. Okay, so now we estimate about constant function. Let's say let's see. So can dysfunction be a constant function? Yes, it's It qualifies for a constant function because it is not changing the properties of the current object. Similarly, print is also constant function. It is not changing the properties of the current object get is also a constant function. It is not changing the properties of the current object. So can dysfunction added to be a constant constant function? No. Why? Because it is changing the properties of the current object. Similarly decide function is also in order Constant function. So operator No, This is changing the property off this current object. No, no, no. Okay, so, Onley, get capacity print and get function. If you want, you can write Name this. Get element again. Okay, so we forgot to test dysfunction before Goto best get element function. So let's best dysfunction also. So let's get see out get element. OK, so see out divan not get element. So which element we want. Let's see the element present that index zero. Okay, so the argument presented Index zero istan. And what if I do? Element presented index five. So the output will be 60 without pretty 60. And what if the index is not valued? Let's say six. So there is nothing president that Index six or let's say make it then. There's nothing president that indexed in, so we'll get to minus one. Okay, so by default, if you see here, we have a dining minus one. So there it is. Done. Minus one. Okay. And furtive indexes negative. So minus 10 again, we will get negative one. Okay. So I think we have tested everything. Yes, I think According to me, we have tested everything. Okay, so we have tested over court completely. So if you have any doubt you can ask me whenever you want. Okay. So I hope you understood this reader completely. Okay. Thank you. 21. Polymoial Class: Hello, everyone. So in this video, I will explain your question that you guys need to implement. Basically, I want you guys to implement a Pelino middle class. Okay, so you have to implement up. But you know, make now. So what is a part of normal? So, in Matt's the example of a problem Ilie's for example, three X square plus four X cube for X to the power five minus. Let's say extra the power seven. So this is the example of a party normally limit so paranormal has two values. So when is the coefficient? So when is the coefficient and the second minister degree? Okay, so in class, in the polemic class, we will store two things degrees and the coefficient. So this is the coefficient and this is the degree this is the coefficient and this is the degree. So what we'll do in the polemic class we will take will maintain a very let's see, the name of there is degree coefficient. So how we will store, for example, if you want to store this paranormal so how we will stole. Okay, So that makes him degrees seven. So it will do. Let's see we have a Neri off. Say seven. Okay. 2345 six and seven. Okay, just a random size. You can take the size of the other to be 510,000. Okay, So the size of their is like, you can take anything. So let's see, the size of their is seven. So how we will stroll this polynomial. So what we'll do for storing, So go to index toe and store tree. So we're doing next to in store three. Go to index Fife and store for so in next, life will store for go to index seven and store when? So I d minus one. So index seven, it will store minus one. Arrested. The values will be zero 0000 Okay, so this is how we will store a polynomial. Okay, So what will use? We will use indexes as our degrees and the values. We will use them as our coefficients. Okay, so this will be already so in this way, we will start our pretty normal okay? And we will take one more day, remember? So just like the our dynamic Eric last, we will keep a capacity also so in this case, the capacity off buries it. Okay, the size that is it. So in this raving restore a polynomial. Okay, so let's discuss the function that you guys need to implement. Okay, So you guys new to implement some basic basic functions, so functions that you guys new to implement. So the first function is D Ford constructor. Okay, so first time writing the name off all the functions that you guys need to implement. So default, then copy constructor and copy assignment Operator. Okay. So whether the fall constructively. So we have to order the members as our private field, so it will initialize the degree coefficient Dari, and it will initialize our capacity. Let's say if you want the size to be 10 so their capacity will become 10 and the Greek option will be new in 10. Okay, so our work is not finished here. We have to move One more thing here, but we have to Do we have to put zeros everywhere in the area. We have to initialize this degree. Compassion directed all the zeros. Okay, so we have to initialized this decryption David. All those zeros you can see here above so 000 So initially, this area, initially this area will contends it only. Okay, then what we do? We will read the polynomial and then we will fill the values. OK, so initially the area contains zeros only. Okay, so you have to do three things inside their default constructor. First, initial, later degree coefficient there in the capacity every and then put all the zeros Port zeros in the legal profession. Very. Okay, so now let us talk about Copy Constructor. Let's take an example. So suppose my polynomial p even looks something like this. That's it. T 10 minus 20 So 01234 Okay, so what is this bull normal? How can you get this paranormal? So three Bless x, My next do X cube. Okay, so this is a purple normal. So if I write, if I'm creating another ball normal polynomial p two p Even so, what will happen? Copy constructor will get called. So since we know copy constructor creates shell a copy. So this pew two pointer will point towards disarray only. Okay, so this is wrong. So inside their copy constructor, we will, But we will do, We will create deep copy. We will create deep copy. Okay, Now let us talk about copy assignment Operator. So if you were right, you to equal Stephen, what will happen? This butto will point towards this area only. So we know Corpus entered Operator also creates shell a copy against. So inside the Corp assignment operator, we will all or the operator equal operator, we will overlord, and we will create deep copy exactly the same function as the copy constructor. Okay, so after creating these three function, let's talk about some more function that you have to implement. So brain function. So how you will print the polynomial that you can see in the caution? I will explain in the question that in which former do you have to like, you have to Ah, print department will. Okay, so after the print function, we we have to overlord some operators. Which operator we will overload, plus operator minus operator and multiply Operator. Okay, so, for plus, operator, we will write something like this. Betray ISP, even bless butto. Okay, so this will go in this it we're going argument and the return type will be a paranormal so how to wear to will normally. So let's see, the problem will be one is just like we used to do in Metz. So for X minus two weeks, the power Fife and we have another problem lp to so minus six. Plus, let's say X square plus X cubed plus extra the power for Okay, So B one plus butto What will happen if their degrees are seem You can hear them so simply three, then minus six. Then degrees are seem so you can add them. You can have the coefficient, so five x squared Bless X cube Plessix to the bar for and minus two X to the power five. Ok, so this really b p one plus p two which is speed three When what you have to do you have to like up there this in the degree coefficient Terry off. You have to obey the degree convection terry off between. Okay, so operate the the Greek option tied off Petri accordingly and same is the case on same is the case for negative subject. So be trees. Be one minus butto. I hope you know how to subtract a below normal if their degrees are seem, you can support the coefficient and for multiplication we have to do similar kind of stuff . We will write with trees, even multiply Pito So the multiplication will be a little bit tough. It will be like a little bit tricky. So first, like you can do it on pen and paper. You can analyze how the things are working and then I would suggest you to write the court . Okay, so this will be like a little more complex, are a little bit complex. And now let us talk about the last function that you have to create. So we have to create. We have to implement a certain coefficient function. So what the SEC option function will do? So this said Cough Shan function. Okay, so how we will write this So even Dart said coefficient. So this third condition function will take two things as input first trimester degree and the 2nd 1 is decommissioned. So let's say B one is Let's see the capacity of six zero when do t four and Faith and lets it of a loser 10 minus two against little when and zero. Okay, so we will call the function. We even got certain proficient, and we will give degree and proficient as input. Okay, so let's say their degrees three and the coefficient is five. So what we'll do, go to index tree and make no confession, Fife. And let's say the values are degrees four and the corruption intestine. So go to index for make the coefficient in over a decommissioned. Okay, we have to override the coefficient. Now the problem will come. Here is let's say, the size. The capacity is six. So the valid degrees are 0 to 5 only. Okay, if the capacities saves, the valley degrees are 0 to 5. And now, if I do degree seven on, let's say the coefficient is 20. So degree seven is not a valid index. Okay, so what? So what is happening here is degree is greater than the capacity. Okay, Degrees garden, the capacity. So in this case, what we will do the vegetable the size of the area. We work double the size of the area and then we will again check. We will check if their degree is less than the capacity. Then it's okay. Otherwise, in the else part, we will again double the size of the area. We will again double decisive. We will again check. Then again, Double again. Check. This will continue. Okay, Bill. Until we reached this condition. So in these two cases, the degree is less than the capacity. So this is fine. But in this case, the degree is good and the capacity So just like in their dynamic Eric class were double the size. But here, after doubling the size, you have to continuously check if the degrees less than the capacity. Okay. For example, eso initially the sizes six. So let's say my value is 14. Let's see the value of degrees 14. So I will double the size. The size will become 12. Then I will check to a less less than 14. So I will again double the size. So 24 now 14 is less than 24. So now we can overwrite the values we can override the coefficient. Okay, so So these all functions that you have to implement. Okay, so let's see where the less structure have accord. So we have a class, but normally so inside the class. But normally we discussed that there will be two private properties. First, the dynamic Carrie. So let's say the name is bigger coefficient and the second is the capacity. Okay, so these are there to private properties. And now what we have to do, we have to create some functions. So the first function is the four constructor inside the fold. Constructive. We have to do three things. We have to initialize decryption initial s capacity and put zeros in the technical efficient. Terry. Then we need copy. Constructor violates copy constructor, because we want to create deep copy. Then we need to copy assignment. Operator, we have to overlord copy assignment operator. Just like Richard in the ah Which class? In the dynamic at a class. Okay, so Korpi, assignment Operator, you have to overlord. So after that, you have to right brain function, which would be very easy. See the question to see what is the brain former. And then you have to said compassion function that will take two arguments. Sorry. Yes, it will take two arguments degree in coefficient. Then you have to overload some operator. So bless operator, you have to overlord negative operator. You have to overload. And then the multi playoff victory, you have to overload. So this will be our structure. Okay, so these all functions you have to implement. Okay. So I hope you understood this question. Good luck. Thank you. 22. Encapsulation and Abstraction: Hello, everyone. So welcome to this new session. So we have already discussed about object oriented programming. But there are few topics that are left. Okay, so let's discuss them one by one. Okay, so there are some concept self. Oops. They are obstruction and kept solution. Inheritance and polymorphism polymorphous. Okay, so in this video, we will try to cover these two. Okay, So we will cover these two in this video. And then in the next videos, we will cry to cover inheritance and polymorphism. Okay, so let us start with the encapsulation. Okay, so let's start with the encapsulation. So what is the meaning? Off encapsulation. So the meaning of thank absolution is clubbing. We have to club things. Okay, So combining things. So what we're doing in cap solution is we will combine their data and the functions, data members and the functions. Okay, So combining the data members and the functions often entity is what we call encapsulation . Okay? Combining leader, the members and the functions of an entity is what we call and absolution. Okay. So we can achieve encapsulation with the help of a class. Okay, so this is nothing better does so With the help of class, we can achieve encapsulation. Let's just take an example. So suppose I have a student class. So industry in the class. Let's say the data members. Let's say the properties are I have name, name of the student age. Let's address. Okay. And similarly, we have functions like settle number and Jane Generous. Okay, so these are D data members and these are the functions. Okay, So if you will combine their data members and the functions orphan entity, then it is called encapsulation. So here we are, combining the data members and functions into a single unit. Okay, so this is a single unit with the help of class. With the help of class, we can achieve our goal off encapsulation. Okay, so now we will cover obstruction. Okay, So let's see, what is obstruction? So what is the meaning? Off obstruction. So the meaning off obstruction is to hide hiding, or we can say hide. OK, so what we will do, we will hide the unnecessary details. Okay. Hiding details which are not important from the outside world. Okay. Hi. Details which are not relevant to the outside world. For example, we ever TV. Okay, So, for example, let us talk about television. So how we will operate television, We will open it TV using the remote. Okay, So with the help of remote, we can perform many operations such as on and off changing channels increased volume or decrease volume. OK, but you do not know what happens internally when you press a button. Okay? We do not know over typos and believing every press a button. Okay, so there is no need for us to know that. Okay? It is not important for us to know what happens when we press a button. So there is no need for us to in overtime payments internally. And let's say one more example. Let's take the example of a car. Okay? So we will know how to drive a car. But we don't know how a car works. Okay, We do not need to know how a car works to drive a car. Okay, so we're hiding. The properties were hiding how our car books from the user, Okay. Usable. Simply come and drive the car. There is no need for us to know how a car works. Okay, so these are the real real example. Now let's see in court. So what we'll do in court? So we all know we have started about sort yesterday about sorting. So we have inbuilt sort functions. So what this symbol charred function will do? It will take a resin put and it will sort the area accordingly. Okay, so we have this inbuilt sword function. We have this inbuilt start function so internally how it works. I don't care. Okay, so what we will do but use every do it will simply call the function sort. And it will give Dari and I revel get sorted Now user doesn't care how internally this sort function book Although we estimate about sort function But there's no need for us toe like there is no need for us to study how a sorting works. We can likely use dysfunction. Okay, So internally how it works, I don't care. Similarly, we have something called STL. It stands for standard temperate livery. So what happens is we have many infrastructures. So the example of the district, just like stacks que hash map and so on. Okay, so we have many of the structures inside the STL These data structures are already implemented. Okay, So many Rita structures are already implemented in standard temperature in standard template library. So what we will do, For example, if I want to create a stack, I was simply write. Create a stack, often teacher and the name of the Stackers s. Okay, if I want to push a limit inside the stick, I will write s dot Push. If I want to pop element, I will write s dark pop. Okay, So I don't care how internally it works, okay? I don't care how internally the stack is implemented in this tender temperate library. I will just use this lanes and I will get a stack. Okay, so we are hiding all these things from the user, so they're disc oil obstruction. So how can we achieve protection so we can achieve abstraction using class? Okay, so let's see. How so? Let's say we have a student class inside the student class. I have name rule number address. So we have a class student and the side that's real class. We have three properties name through a number and address. Now what I want to do is I want to hide the rule number from the outside world. Okay? I want to hide this property from the outside world. So how we will do it in a class simply We will make this property a private property. Okay, So making the properties as private properties. This is called obstruction. Whenever we make a property private, this will not be accessible to the outside world. Okay, so this thing so making the properties, If you make properties private, then we call it obstruction. Were hiding the property. Okay, so we can achieve abstraction using the class. If someone wants to access the rule number, it has to call a public function off this class. So we will create a public function of this class. And if user wants to access the real number, you can access the real number with the help of the public functions. OK, but this property is directly not visible to the outside world. Okay, so we are hiding this property. So we have discussed or disaffection and how we can achieve it. Now the question is vibraphone to hide details. Okay, bye. We wont to do obstructions. So there are two main reasons for doing eff sections and the first reason is so the first major reason is abdication or changes. So what happens is if we change our own cord, then and he's of course would not be affected. Okay, So if we change our own cord, then use a court should not be affected. So suppose I ever saw it function. This sort function will take areas input and it will sort theory. Okay, so let's exhume initially, the sword function internally uses bubble sort. Okay, Lets says, um, we know this is not right, but let us assume initially this sort function uses bubble sort. So how will user call this function? It will write a usable call. The function in this manner sort and it will give dairy. So now, after some time, we realize that bubble sort is north and efficient sorting out your dumber days and square . So the changes we change internally how to sort out the sort function work which in just a bubble sort into quick sort. Earlier, we usedto use baba sort. But now we're using quick sort inside this heart function internally. Okay, So if I am using quick start now, so will use a court will be affected said output is no. So the answer is no is accord will not break. Okay, if user has rights and program inside the program, if the user is using disorder function. And if I changed the internal working of disorder function than user called will not be affected, use a court, will Lord big. Okay, so this is the first reason why we do obstruction. Okay, So if we change our own court, then use a court should not defector now, the second main reason is to avoid actors. Second, major reason for doing instruction is to avoid others. So how can you avoid at us using extraction? So suppose this sort function is a public function. So if this is a public function, what will happen? Animal can come and change it. Okay. And here numbers and can come and it can change the internal properties of disorder function, internal logic of the sword function. Okay, So what will happen using can introduce others in ever called. OK, but you don't want one dissenters. So what do we do? We will make the sort function private. Okay, So what we will do? We will hide the crucial properties Since we relied the crucial properties. You user cannot come and change those properties, so use it cannot introduce those others in our court. Okay, so we should always do abstraction. Okay, so this is all about obstruction. And next to redo, we will discuss about inheritance. Okay. Thank you. 23. Inheritance Introduction: Hello, everyone. So in this video, I want to discuss about inheritance. Okay, So what is the meaning off inheritance. So in items means to in added some properties from our parents or ancestors. Okay, so just like the human, do what we do. We all in arid thumb, correct districts from our parents or grandparents and tim properties or qualities are our own. Okay, so let's say in cold. So suppose I have three classes. God, bicycle and I have a class look. Okay, so the properties off car class are color color of the car. Maximum speed off the car and let's say the number off gears. Okay, So number of guests and louder this talk about the properties of bicycles, so color of the bicycle Mex speed, and obviously bicycle doesn't have gears. So let's say we have a 1,000,000,000. Property is four levels, so some bicycles therefore level. So we have a property 1,000,000,000. Property is for level. Okay, Now, let us talk about truck. So color of the drug makes spirit of the drug and some other populated properties. Okay, So what is happening here is some properties are common in many classes. Okay, so common Goldman and common. Okay, so these properties, some properties are common in many classes because they all have one feature in common. All three belongs to vehicle. Okay, all three article. So what is happening? It is. So I have a class vehicle. So all the three things guard, bicycle and truck, the 11 feature in common, All three articles. Okay, so now my aim is I have to create these three classes. Okay, so I have to create three classes car, bicycle in truck. So the first trays, just like we created these classes. So the first rays, we will create classes in this manner. First, some common properties, then college it properties. Then again, some common properties, then by simulated properties again, some common properties and then regulated properties. Okay. Now, the second year to create these three classes in a good vein, A in an appropriate way, it's what we will do. We will move these properties inside difficult class. Okay. So that we could cause will have color. And the vehicle will obviously have the Mexico speed. Okay. And we'll remove it from here. Okay, So remove these things from the bicycle class, remove the common properties from the for a class. Okay, so we have to move common properties. Too difficult class. So vehicle is our parent. Recall is our parent close and car is a child. Child class. Bicycle is a child. Close. Broke is a child class. Okay, So what really happened? The car Dallas will have some car specific properties and the common properties it will inherit from its parent. Okay. Similarly, bicycle will have some properties off its own by simulated properties and other properties it will inherit from vehicle. Similarly, truck will have some calculated properties, Prock specific properties and the common properties it will inherit from experience. That best difficult class. Okay, now, suppose I want to create one more class here. Okay, So I want a great one more class. Let's say the name of the classes bike. So the name of the classes bike. Now what bike will do? It will inherit summer common properties. It really married. Color in the mix speed from the victim's loss and some properties. Visibility toe the bike specific properties. Okay, so the second way is the most appropriate way to create classes. Okay, so what? Our approach move Common properties to a common class to one class. Create one class, which is the parent off all the classes and move the corn properties there. Okay, so let us take one more example to understand it better. Okay, so suppose I ever teach a class and I have a student class teach a class and student class . So now let us talk about some properties of the teacher, so teacher will have a name. Age of the teacher will be a property similarly address contact number and lets the qualifications we're at the qualification of their teacher expertise. A DEA. So these are some properties of a teacher. Now let us talk about the properties of the student so a student will have a name. This trend will have age. Similarly address. Contact number. Astronaut will have rule number, badge number and so on. Okay, so now we can see here again. Some properties are common. Name, age, address, contact number. And here also some properties are common. Okay, so now we work. We will do. We have learned about inheritance. We will create a new class. We will create one class. Let's say the name of this class is human class. We will move the common properties here and will remove the common properties from here. Okay, so remove the common properties because the common properties will now belong toe human class. So human will have name at rely of age. It will have address and it will have contact number. So teacher class will contain only teacher specific properties. Student class will contain only student specific properties and all the other properties. But it will do it will inherit from experience. Okay, so we will inherit the common properties from our parents again. We will netted some properties from our periods and some properties will be our own. Okay, so you narrating common properties. Okay, so human is our period class. Human is our period and teacher and student, they both are child child classes. Okay, So what is the main purpose? What is the main benefit off? Using inheritance. So the mean benefit off using inheritance is reusing the cold. We are reusing the court. Okay, So move all the common things at one place and whenever they're commenting, is acquired, just inherited the common properties. Okay, so this is the main benefit of using inheritance, reusing the court. Okay, we will. Just like the court wants. And if someone wants those properties, just inherit the properties. Okay, so the main benefit off inheritances are using the cold. Okay, now, let's just talk about excess modifiers. Now let us talk about excess modifies So we already know about to excess modifies public and private. So we have all illustrated about private and we have well illustrated about public. So private means it is not accessible outside the class and public means it is accessible to anyone outside the class. Okay, so they both are very extreme. Private is very strong, and public is very lenient. Okay, so we have warned something in between. And there's something in between the public and the private is called predicted. Okay, So what is predicted? So what will happen? Let's say I have a class and inside the classify declare a property X, Toby, a protected property. So what will happen? So this protected property is accessible to someone outside the class and is not accessible to the others. Okay, so if I declared a property X are protected property for this protected, Roberti will be accessible outside the class for only for some people. And for that it will not be accessible. Okay, So X is a property. I've owned the property that should be accessible for some person and not accessible for the rest of the world. So we will declare their property as a protected property. Okay, so let's say I have two classes. Class A and Class B class is apparent. Class and class being is a child class. Okay, so be in arid some property from me. Okay, so let us take the calen carr. So I have vehicle and car, so card is a child class and vehicle is apparent. Close. Okay. So card will in added some off its properties from the vehicle fears. Okay, So what will happen if a property is protected, then it is only accessible to its child class, so let's just take an example. So suppose this is vehicle class and inside the vehicle class, I have declared a property X as a protected property. So what will happen? So this protector property X is accessible outside the class, but only for those classes which inherited from the vehicle class. Okay, so this protector property X is accessible outside the class, but only for those classes which inherited from Victor class. That is only the child classes off the vehicle class. Okay, so over time, saying it is. So what I'm saying here is let's say every vehicle class. So I have a class vehicle inside the vehicle. I have a public property X by ended. So excess public values, private ends. That is predicted. And this is outside. Okay, So public property ex and even Connexus public property X outside the class. Okay. X is accessible for everyone. Okay. Anyone can access Anyone can access X because accept public property outside the class. Private property by no one can access the private property by outside the class protected property, is it? It is accessible outside the class, but using on little child glasses using only it's child glasses. Okay, So public property, ex and even Connexus outside the class, no one can access outside the class. It is accessible outside the class, but using only its child glasses. Okay, so suppose this is our vehicles loss, and there are three other classes which in added from the briquettes loss and these are car is a child glass of vehicle Bicycle is also the child glass, optical and truckers Also the child Philosophical similarly. Let's say I have a class human so human teacher and student inherits from human. Okay, Now let's talk about protect Critical Pretty is it okay? So obviously Vical can access the protective properties Erred car can exist The protected property bicycle can existed and truck can access. It'd by because the oil our child classes or difficult class so human cannot exist That teacher cannot access it and student cannot access it. Okay, so this is human Cannot access Student cannot exists and teacher cannot access the protected property. Is that off the record class? Okay, so if you want to exist the protector property there should be a relation between the parent class and the child class. Okay, so I hope you know what This protector now so protective properties only accessible using its child glasses. Okay. Since human does not have any relation with the vehicle so it cannot access said, If human cannot exist then obviously a teacher and student the also cannot access. Okay. Thank you 24. Inheritance Syntax: Hello, everyone. So in the last video, we started discussing about inheritance. I hope they're dis cleared. So So what we have is so we discussed. We have a vicar class, and we have a class God car glassful inherited from the vicar class. So we called vehicle class as based class or a brilliant class, okay, based class or period class. And we will call the class car as derived the class or child, Gus. Okay, so in this video, we will learn about dinner dancing picks. Okay, so let's start. So we have a class vehicle. So this classical has three properties. Mex feared number of tires and color property. So the Mexico property is private. Number of ties, properties, protected property and the collapse properties the public property. Okay, so? So since the Kaletra produced a public property, it can be used anywhere inside or outside the class. Okay, So number off nice properties are protected property so it can only be used in the derived class. It can be used inside the vicar class. And if you want to use the protected property outside the class than it will be used only in the delivery classes of difficult loss. And since the Mex properties, private property, so it cannot be used outside the class. It can only be used inside difficult class only. Okay, so now what we will do, we will create a class car. The class Carvel inherited from the victory class. Okay, So what will happen? So virtuous antics. So first we write the keyword class, then the name of the class, which is car Ben column. Then we will write excess specified. Now, this excess specified can be public, private and protected than the name of the class, which you're doing had it. So the name of the classes we call, and that's all. So this is this index for inheritance. Okay, so the really off excess specified. It can be private. It can be public, and it can be predicted. Okay, So what is the meaning off excess specified? So it will specify how we will be able to exist the properties off the base class. Okay. It specifies how we will be able to exist the properties of the base class. Okay, so let's see in court. So, class car column, then the excess specify. Let's say the excess. Specify this public, we will see private and protected also. But for now, let's say the expressways, where is public and the name of the class, which is a vehicle. Okay, So what will happen if I if I read this much? Cool? So what I'm having here is So when I read this line Line number 16 what will happen? So I have this class so we could class and I have another class, so discusses card. Okay, so I have some private properties. I have some public properties and I have some predicted properties. And what I'm doing at Lane number 16 the excess specify this public. So we are inheriting publicly. Okay. Class card is being inherited publicly. So what will happen? So private properties, they cannot be used outside the class so they cannot inherit. We cannot inherit private properties because we cannot use them outside the class. So what will happen to the public properties? So the public properties will become the public properties off the carcass. Similarly, the protector properties will become the protected properties off the carcass. Okay, so at this moment, virtual the structure of the car class. So the structure of the car class is something like this. This is guard close. So inside the private, we have nothing. Okay, so inside the protected field inside the predicted members, we have only one member, which is numb ties, because off inheritance. So prickly predictor is and I'm dice. And inside the public properties, we have string color. Okay, so we have color. So this is the structure off car class. Okay. After line number 16 this will be the structure of the car class. Okay, So one second, private properties never inherited because they cannot be used outside the class. Public properties will become public members. And similarly, the protector members will become the protector members of the car class. Okay, so this is the case when we are inheriting publicly. Okay, So this is the result off in evidence now, car class can also have its own properties. Okay, so let's in court. So let's say car class has some public properties off its own and lets it the name of the properties number of gears. Okay, So numb gives. Okay, Now, let us know what will happen at this line. What is this? An accurate this lane. So this is Scott of the US Private. We don't have anything inside the predicted we have one property which is number of tires. So numb tires. And inside the public, we have two properties now. So when it's due to inheritance, which is color so this is due to inheritance and the second properties the property of the car class. So it is number off gears, numb guests. Okay, so although we can see only when properties, although we can see only went property inside the car class. But actually we have three properties, number of tires, color and them gives. Okay, so let's say the print function. Okay, so let's trade the print function wide print. Now inside the print function, let us try to print the value of number of bias. So see out so lay number 20 minutes, correct? None. Class car property has the property number of ties. Okay, so let me first right, everything. Then we will see what the provider, the properties that we have and we let the properties that we don't have. Let us try to print color and let us try to print the number off gears or solar destroyed to print Mex food, so see out may explode. Okay, so what is this scenario? So we have a glass car. So inside the class card inside the private properties, we don't have anything for predicted. We have a number of tires. Newdow in evidence you do inheritance publicly. We're narrating publicly. So number of tires and inside the public, we have two properties were missed due to inheritance, which is color. And the second Manistee property of the car class, which is number of gives numb gays. Okay, so this line is correct. We can access number off diets. Why? Because number of nice is a protected property and predicted report it can be used inside derived class. So it is correct color. We can access color because it's a public property. We can access number of gates because it's a public property. Can we access make speed? No, we cannot access makes speed because class car does not have any Mex breed property. Okay, so if we will win this fight, we will get another form X speed. Okay, so let's see. Let's trader in this file. So we will get an error. Makes me Let's see, what is there So we can seem XP this private. Okay, So inside different function We are getting better. That makes beauty is private. Basically, it will not be inherited. So the class got Roberti doesn't have any property. Max. Speed. Okay, So what? What is happening now? It is. So when we do when the car class in adults Publicly, When the excess specify this public, what will happen so the public properties off the vicar's loss will become the public properties off the car Close. Okay. The protective properties off difficult class are now also that protected properties off the car class and the private properties, since they cannot be used outside the class, so private properties does not participate in inheritance. Okay, so this is the scenario. Okay, So let's try to create some objects off the class and let's see. So this this Linus, this land will not work. This is wrong. Now let's turn this file. So this time our court is running. No, I did so let's create some objects off the vehicle. Plus so we could be So can we exist? The collect property, read or color? Let's see the calories blue. Can we exist? The MEC spirit property. Let's say we don't make speed is food and V dart number of tires is Let's see again. Food. Okay, so if you will win this file, will you get in a year? So let's try to understand. So we have a classical so inside the because loss in the private properties what we have We have Mex food for the predicted Robert E. We have no more of tires, numb tires And inside the public, we have one living property, which is color. Okay, so we don't kill articles Blue. This is right, because the Polaris public colors for Blake. So this is right. Very dark May experience for Is this right or wrong? This is wrong. Because Mexico is a private property, it can only be used inside the vehicle class. Okay, number of ties. So this is a protected property number of Tizer predicted Robert E and protected property can be used inside the vehicle class. And if you want to use number of tires outside the vicar class than it can only be used inside, did they have the classes? So we cannot use it inside the mean Okay, So line number 30 in line numbers are given. Both are wrong. So we will get better if we're in this. Well, okay, let's see. So this time we will get to others for them. Experian for the number of bias. So the other is first. That is due to Max speed because an expert properties private. And the second that is due to a number of times because it is predicted okay and brittle. But but it can be used. Insider. Did I have the glasses? Okay, so let's make its commander doubt. Now let us create the object off car class. So, karsi let us try it on the standard color property. So the collab properties deep public property so we can access it. Let's see the hilarious black. So can we exist? Number off diets, property, numb dice. Roberty. So let's say the number of ties is for so can we. Excess number of Thais property. The mufti eyes were produced a productive property. Let's see, and sometime. And let's say the number off gifts. So number of gears, our faith. Okay, so what will happen if you will run this file? So the structure off guard us. It is very simple inside the private. We don't have anything. And inside the protected property we have one property due to inheritance. And that property is numb tires. And said the public, we have two properties. One is due to inheritance which is color. And second is the property of the car class which is numb gives Okay so we can access color because it's public. We can access numb girls because it is also public. But can we exist? Number off tires. It is a protected property and predicted property can be used inside their derived class and we're using it inside the mean. Okay, so let number 35. This line will throw us enter. Okay, This land will throw center. Let's see. So if you see, we will get better number of Thais. Property is a predicted Robert E. Okay, see that I number 35 at evidence. The statement Number of dices predicted property. Okay, now let's commander doubt. Okay, Now let's in this file. So our final is running without any other. Okay, so So we have this Roberti car. We have this class car private. It is empty. Predicted member is only one which is numbed. Ias and public. It has two properties color, and the 2nd 1 is numb gives. Okay, So what will happen if I inherit car class publicly? Let's say I have a class Horner city. So this is how industry to class and ethnicity class is inheriting car class publicly. So what is there? Will for publicly first of all, private properties do not participate in inheritance so private will be empty. Okay. And since we're uniting publicly, what will happen? Protected will become protector. So protected property it will contain them dies and public will become public. So public have two properties color and numbers. Okay, so this is the case when the Honda Civic Class is narrating the car class publicly. Okay, we have two more excess pacifier. So in this case, doesn't Texas God's Honda class ethnicity, public excess specify and God. Okay. So we can use private and predicted head also. Okay, we have three xs specify public private and protector. We have seen the court for public. No. Let us try to understand what will happen in the case. Off predicted and brave it. Okay, So Okay, So this is our because the us and this is car close. And this is vehicles. Last send. This is car class. Okay, so we have private. We have predicted and we have public. Okay, So if the car class it the vicar's loss if we inherited the vicar's last protected using the access misfire predicted, what will happen? So first of all private properties do not participate in inheritance. Okay. And what will happen? Protected properties will become the predicted properties, and the public properties will also become predicted properties. Okay. Now, what will happen if the vicar's loss every used excess specified private, so this has very it predicted and public. So private properties do not buy displayed in inheritance. Predicted properties will become the private properties, and the public properties also will become the private properties. Okay, so this is the gays, fourth predicted and private. Okay. Know what will happen if the car class is being if the whole tenacity class is inheriting the car class. So we have a Honda City class and let's say the excess specified this public. So what will happen since this car class has the private properties and pirate properties do not participate in inheritance. So the Honda Civic Class will be empathy. Okay, so nothing, nothing will be inherited. Okay? Because car class only has private properties and private preparation or participate in the nineties. So when does it kick? Class will be empty. Okay, now we're lasting. So everlasting is here we are using excess. Specify public. Now, what will happen if I do not mention any excess specified? Okay, so by default, the excess modify it is private. Okay, so what I want to convey here is so if I will write laskhar column vehicle if I do not to mention any excess specified. So by default, the excess specified is private. Okay. By default excess specify this, private. Okay, so I hope everything is clear now. Okay. Thank you. 25. Inheritance Order of Constructor and Destructor Call: hell ever. Even so, in the last session we discussed what is this index for using in evidence? I hope that by this clear now, let's see the court. So at lane number 28 I'm creating the object off vehicle class. Okay, so what will happen? So this is our vehicle class, and these are some of the properties. So at this line, line number 28 what will happen if oil construct of difficult classical? Because which will initialize the properties of difficult class? No doubt. Now lie number 33. I'm creating the object off car class. Now. Car is a special class. Why they special Because of the night from difficult class. Okay, so this is our car class. And inside the car class, we have some part off difficult class and some car specific properties. So the parties we have color and we have numb tires. The third property, which is theme expert property, will not be inherited. Okay, So for creating the object of the car class, we have to create this vehicle class for creating car class. Object. Okay, So before creating card last subject, we have to create this vicar class object So we have to initialize all those properties and that are accessible to the car class. Okay, so when we write karsi so s own is as soon as we create this car class object than first ofall vehicle class Constructive will be called Okay, it will be called automatically. It will be implicitly called. Okay, And then the car class will be called. Okay, so via the victory classically recoil first. Because first we have to create this part. Then only we can create this outer block in the memory. Okay, So when we write car, see what will happen first, the vicar class constructed will be called so that we can initialize. We can create this part in the memory in the car constructor will be called so that we can clear this outer block in the memory. Okay, so but with the order of calling constructor in gets off in evidence. So what will be the order of calling constructing case off inheritance? Suppose we have three classes glassy class B in added from class A and glassy in added from glass B. So if I create an object off glass, he then what will happen only the e class constructive will be called. Okay, so this is a and it has some properties. So only the e class Constructively, Bacall, no doubt. Now, if I create the object off glass, be, then what will happen? So this is the structure for class B. It convinced e and some be specific properties. Then first of all, what will happen, Constructor evil Because and then construct a b will be called. Okay, so first a class constructively. We called then because constructively recalled because first we have to create this part. Then we can create the outer part. Okay, Now, if I create the object off C class than what will happen First of all, this is the structure off Gosse. It convenes be and some see specific properties and we contains a and be specific properties. So first of all, we have to create a So a class constructed will be called. Then we have to create be so this be class constructive will be called. And at last, this c class constructed will be called. Okay, so I hope that you now understand the order of calling constructors in case off inheritance . Okay, Now let us verify every statement. So let's in court. Okay, so let's make some constructors. So I am creating our default constructor. Okay, so the Ford we call constructor and now inside the constructor alerts, friends something. See out the cave defiled constructor! And now let us also create their default. They're the four destructor for vehicle class. Okay, so with special symbol and vehicle the girl destructor. Okay. And now let's do the same for car class also. Okay, so we will create the car class, the foil constructor and district in constructed. Okay, so card. Now let us bring something. See out! Car defied Constructor! And now let us also create their destructor. Okay, Okay, so we have vicars, class defied, constructor and destructor. Similarly Car class or devoid? Constructor and destructor. Okay, now what will happen? So at this lane, what will happen so v class default constructive will be called. Okay, so vehicle class before constructed will be called. And at this lane Karsi, What will happen first? The vicar class before constructively recalled, And then the car class default constructed will be called. Okay, now let's in this file to see the output. Now it's coming. Everything out. Okay, so the cull V and karsi dollars in this. Well, okay, Now let us try to analyze what is the output? So first the vehicle class constructive will be called now, this constant place being coiled for creating the ticket class subject. Okay, so this first output is due to a vehicle class now, The second our POTUS, we are creating the car class object. So first the default constructively. Because then card constructively called. Okay, so the first line is due to vehicle class. Now, the next to line are due to car class, and the order for destructor is just deposit. Daughter of the inheritance. So first the car destructively recalled then vehicle destructor. So these are due to car class, and the last line it is due to weak class. Okay, so the order of destructor called is just the opposite of the inheritance. Okay, so the first lane, this is due to vehicle class. The next to line this is your new car class again. The next two lane are due to car class destructor, and the last line is you do have the class destructor. Okay, So the order for district placed up was it off the order of the inheritance. Okay, Now what is happening here is so at this lane implicitly, what happens is it is something like this. So we have started about initialization list. So what is happening? It is when we were writing car, see what will happen. It will call its default constructor. So when we will reach this default constructor, it is implicitly something like this initialization list. Okay, so what will happen? What is the use off initialization list? So before and bring this constructor before reaching line number 29 we will goto the vehicle constructor. Okay, so that's why this court is getting printed first. This scored the codified cancer plays getting printed first. Okay, so okay, so implicitly. This is something like this. But you do not need to write this here because the vehicle class before construct rate is called implicitly or get the school automatically, so we don't need to write this, okay? No. What will happen if I create a perimeter raised vehicle constructor? Okay, so we have a better motorized vehicle, constructor. It takes an argument. Let's is it. And what it does is Max Beard is zig Okay, So what will happen now? Okay, So what happened is So when we write Garci, what will happen? It will call their the foil constructor of difficult class. Okay, So always their default constructively. Because automatically. OK, but if you want to call the betterment ties construct of the vehicle class, then we have to call explicitly. Okay? I'm debating myself when we write Carsey what it will do, it will call their default constructor of D vehicle class. But now what I want is I have a better motorized constructor. Param. It placed vehicle constructor and I want to call this betterment race concept. Er I want to call this perimeters. Constructor. So what we have toe? Do we have to call explicitly and this is implicitly We don't need to write anything. This will recall implicitly but for calling the paramilitaries constructor, we have to call explicitly. So what is the Syntex? Certain Texas? Very simple. We will write Carsey then with the help of initialization list vehicle. And since it takes on living argument so we give one argument, okay? And that's all. Okay, so this is this index for calling the betterment days constricted. Okay, and for the fall constructors in Texas were simple karsi and simple vehicle. OK, but in case of default, we do not need to write this. Okay, now let us call the perimeter Ize constructor. So I want to call this pattern. It is constructor, so I have to pass a value. Let's say five. Okay. And now this is correct. OK, burn something so that we can very fe. So is he out? We could paramour traced constructor. Okay, so now let us come in and out everything. So to avoid any confusion. So we have only car. See here. Now we will try to analyze for Julia Output. So Garci, it will be will reach here. Garci on initialization list. We are calling the paramilitaries constructor off difficult class, so we will reach here. So the output will be vehicle paramilitaries constructor and then guard the false constructor. Okay, so this will be our output and then the order of district various Just deposit of the order off inheritance. Okay, so now let us turn our file. Okay, so we can see here is vehicle perimeters Constructor called then Cardiff Old Constructed called and the order of District plays deposit first, the car will be destroyed and then the vehicle will be destroyed. Okay, so everything is running fine. Okay, so now let's take more examples. Okay. So OK, let's remove this. And now let us also comment. The vehicle defied constructor. Okay, so I'm commending out we called the foiled constructor. Okay, so now they're default. Construct off the vicar classes north visible since we have created our own paramour Traced constructor. Okay, I'm repeating myself since we have created our own betterment lies Constructor, the Vicar Class default constructors not visible to us anymore. Know what will happen. Can we create our car class object now? So will this line work? Karsi? Will it work or not work? So without protest, it will not work. Okay, Let so let us in this file. So we will get another. And now let us try to analyze what is the otherwise We are getting an edit. Okay, so when we write karsi what it will do, it will try to call their default constant. Probably because last and their default construct of the vicar class is not there because we have created our own parameters, constructor. So this line is wrong. This line will through a center, so we cannot create objects of the car class now. Okay, so what we have to do? So here we have a compulsion. Okay, So now, in order to create a car class subject, today is a compulsion. Now that we have to call the Paramount trace constructor or difficult last, because the default when it's not visible. Okay, so here we have a compulsion. In order to create the object of difficult class, we have to call the paramilitaries constructor or difficult class, because that the fall concert political class is not there. Okay, now disconnect. If you will render file, they will not get any of it. Okay, so our court is working without any others. Okay, Now, this is not the right way. So what is the right way? So the right ways. First we will take the input and then we will pass the X hair. OK, so this is the right way. Now, if you will, Right? Karsi, We have to change this also because cars, they will call the default constructor. And we do not have the full construct that we have paramilitaries. This is Noah Parameters, Constructor. So this change. Okay, so we cannot get objects like this because we do not have the fall constructor. Because we we have created our own perimeters constructor. So in order to create the object, we have to pass a value. We have to call parameters constructor. Okay, now let's on this file. Okay? So everything is working Fine. Okay, Also know let us try to enlist output. So first the vehicle class paramedics constructor will be called then car parameters constructively because and then the order of the strict place deposit. Okay. Okay. So now let us take one more example. So now let us create another class glass horn density. Okay, so this glass from the city let us inherit this class inherits from the car class. Okay, Now let us also create. It's constructive and destructive. Okay, Aren't sed constructed are necessary Defied constrictors Better. Okay, so let's leave it on the city construct only and every little so clear or less City district. Er Okay, so now we have three levels off in evidence now. Okay, So what we have is we have this vicar class guard glass inherits from the vehicle class and their own Nasuti class and hundreds from the car class. Okay, so three levels off inheritance is there now. Okay, so venereal, Create the audacity object. So if I write are not 30 edge, then what will happen? First of all, it will call. So what will be the order off inheritance? Okay, so first the vicar class subject will be called the cook last construct. It will be called then the car class Constructively we called and then the only city constructively. Because so this will be the order Now what will happen when we write the subject on the city age? What it will do? It will reach here Lane number 40 it and implicitly what will happen? Car class before constructed will be called. Okay, so we will call car class default constructor and card Last default constructor is not visible to us. Why? Because we have created paramour ties Constructor. So we will get another. Okay, so this line will through other why it will throw it Because the car class default constructed will be called And the card last fall Concert place Not there. Okay, lets see diet. Okay, so let's come and out everything. So we are creating an object off or necessity. So what it will do? We will reach this line for dear. It will call the cart Last default constructor and the car class default construct! It's not there. Why? It will call car class default constructor, because implicitly before constructor is called. Okay, so we will get an idea. Okay, so we're getting another now in order to resolve the center. What we have to do since we only have paramilitaries Constructor! So we have to call this paramilitaries Constructor! Now there is a compassion here. We have to use the insulation list. So Car five in order to call in the perimeters. Constructor! Okay, so now it will work. Okay, now we have to explicitly called paramedics. Constructor! Now lead, sir, in this file. Okay, So what is happening? It is This is Door Did. First the vicar class Paramedics constructor, then car buyer, my price constructor and the whole city constructor and the order of District place deposit . Okay, so everything is running fine. No, If I want to pass perimeters, suppose I won't go past perimeters. So karsi and and way so X will go Do the vicar class and four way, but we are planning to use here is, let's say, a number of years number off gears is why Okay, now what will happen here is since the car classes now taking two arguments has input. So let's say this publicity class it takes two arguments extend way, OK, because the car class constructed takes two arguments toe will pass X and we will pass way okay now for creating the Honda City object. We cannot create object like this because it will call the default cancer parent if all construct is not there because it's a perimeter ize constructor. Now Okay, so we have to call Param attest Constructor, we have to pass to reduce use every pass to values Letter to values are four and five. Okay, so what will happen para medicinal susceptible? Because so we will reach your X and y every bit past tow the car class perimeters constructor So number of games are by animal past X. So from here we will reach the vehicle class and festival because last paramedics constructor called then car glass betterment lies construct the gold and then the homeless city constricted called so this will be our put. Okay, let's on this file again. So, first of all, we could class parameters constructor than car and then Honda City and the order of district based just deposit. Okay, so when lasting. So when last thing is so we have this working class car class inherited from biblical class and the homeless Utica and the ethnicity class inherits from the car class. Okay, so a class can only call the constructor off its immediate didn't. Okay. Ah, class can only call the constructor, offer its immediate parents. So this is right. And this is wrong. Okay. Our class can only call the constructor off its immediate billions. Okay. Similarly, car class can call the construct property with class, but don't acidic class cannot call the constant property vehicle class. Okay, so that's all from my side. Thank you. 26. Inheritance Types: Hello. Even so, in the last video, we discussed how constructors and distracters are calling gets off in evidence. So in this video, I want to discuss different types off inheritance. Okay, so the 1st 1 is single inheritance. Now, what is the meaning off single inheritance. So it means on leave one parent and one child. Okay, so Class B in marriage classing So one parent and one child vehicle and God. Okay, so only one parent and well, child. So where is this? In Texas? In Texas. Quite family. The ice guard, then excess mortar fire. And then the name of the class, which is vehicle. Okay, so this is this index for single inheritance? No, the second is we have multi level multilevel in evidence. Okay, so what is the meaning? Off multilevel nineteens. So in multilevel inheritance, we have multiple levels. Okay, so for example, glass be emitted from glass. A glassy inherits from class B and so on. Okay, so we're took an example in the last session so we could class. This car class inherits from the recruit class and then we have 100 30 class which in marriage from the car class Okay, so how? The properties will be accessible. So when it depends upon the excess modifies you use, Okay, now, the 3rd 1 is now the 3rd 1 is Hi, Erica. In the evidence. Okay, so, Heracles in evidence. So what is the meaning off heretical in evidence. So in this case, we have one parent and multiple child. Okay, So only one parent will be there, and there will be multiple child B C and the Okay. Now let us take an example. So we have a vehicle class guard class in its chemical class bicycle class inherits from the weaker class, and similarly, that class will inherit from the secret class. Okay. So much deeper Class inherits the base class. So what is this antics? Those in Texas? Quite family. And for example, if you want oh, use track Lascaux class truck, and then public vehicle. Public is TXs modifier. Okay, so let's say in court, although the court is north necessary, but let's see. So I want to create a class class truck now this glass truck and its excess modified this public and return at its from the we could class. Okay. And that's all. OK, so we can see here is glass card, which also notes from the vehicle class and similarly in there's a class truck which also in aid from difficult class. Okay, so this was hierarchal inheritance. Okay, Now let's see the next one. So the next one is the four twenties. Now, this is somebody level multi level in evidence. So what happened in multilevel? In evidences So one class will inherit from multiple base classes. Okay. One class will inherit from multiple base class writers E A B C. And there's a class B so one class will inherit from the multiple based classes. Okay, so suppose we have teacher teach a class and student class, and the 3rd 1 is the teaching assistant. Okay, so teaching assistant will have some properties off. Teacher and teaching assistant is also a student. Okay, so one class will inherit from the multiple base classes. Okay, so let's see in court. So I have this class multiple inheritance toward CPP. Sorry, I have this file my culinary desert See PP. Let's create two classes. So class teacher. So this class teacher has some public properties. Let's say the properties are name and each Okay, so string them and let's see. Bandage. Also, let's say there's ah, brain function word print inside the brain function words sprained something. Okay, so see out, teacher. Okay. Knowledge is also create a class student. So we have a class student now. This student class. Let's see, it also has a function, Brent so worried print. And now that the sprint student inside the print function so a student. Okay, now we have a class teaching assistant. So this class teaching assistant, as you can see here, this class teaching assistant it in attitudes from both the classes, it and it's it inherits from the teacher as well s from the student class. Okay. And let's say the excess specify iris public. So class teaching assistant, The syntax is very similar. First, we have to rate the excess more than fire. Let's say the excess more than fire for their teacher class is public. Then comma again excess specified for the student class and then the name of the student class. Okay, so this is this index for multiple inheritance. Okay, So this class teaching assistant it in ads from both teach a class since rent, class and for both the excess. Specify this public. Okay, now what will happen if I want to create an object off their teaching assistant? So teaching assistant, let's see the object busy were the name of the object. Is he? So what is happening here is Okay, so we have teacher and student. So I have a class teacher and I have a class student and then I have a class teaching assistant Internet. It's from the teacher and the student. So this is teaching assistant glass and teaching assistant class inherits from teacher as well as it heads from student. Okay, now what will happen when I read the statement when I'm creating the object of the teaching assistant class, then who's constructively be called first? Okay, so it emanates from teacher and it and added some student from both the classes. So who's construct people be called first teacher or student? Okay, So down, said his teacher. Why did turn? Because I write teacher first. Okay, so because I write the name of the teacher class first. So that's why first awful teacher construct people because then student construct a bill because and finally they're teaching assistant construct table because when we are creating the object of the teaching assistant class Okay, Now let us try to knowledge tissues, the brain function. Okay, so now leads called the brain function. So what will happen? Okay, so if I run this failed, they will be another. Now let us try to understand by the every welcome. So what is happening? Areas. So, first of all, the sprint function is accessible for teaching assistant. Why? Because, as you can see here is brain function is public. And similarly, the print function is public here and we're using the excess. Specify public. So teaching assistant has access to the print function. Okay, now what is happening? It is we have a teaching assistant class and in their teaching assistant glass we have a teacher and we have a student and teacher class has a brain function. Similarly, student glass also has brain function. So when I am calling the print function, I'm telling you they will be in error and by there will be there because there is ambiguity who sprint function to call compiler will get confused. Ok, So compatible. Get confused. Among whose print function to call the heparin function off to rent print function. Okay, so that's why I and everybody here. If the print function is present in one class, then there will be no other. Okay, so suppose if the print function was not present here, then obviously there will be no other. Obviously. Then this sprint function would have been called. OK, but what is happening? Areas. Both the teacher and the student classes. They both have the print function. Exactly the same name. That's why the compiler will get confused. Because there is ambiguity whose print function to call. Okay, so if you will run this fail, we will get another. And I will be saying Like Like, there's some ambiguity in the brain function. Okay, so let's traitor in this file, Okay? Soviet guarding it at this line. And there will be something like print function present in multiple based classes. Okay, so we have to base classes, student and teachers. So we have to base classes and the brain function is present in multiple base classes. Something like this. Okay, now, how can we resolve this issue? So tour is all decided. We have to specify the class name. Okay. Suppose I want to call the print function president in this student class. So what? I will write a dart student name of the class who sprint function. We have to call and the scope resolution operator. OK, now, this time I've ever run this file, there will be no other and output will be student. Okay, This this brain function will be called. Okay, so this brain function will be called Okay, there straight on this file. So story investigating printed. Okay. No. What if this teaching assistant Glass also has the function brain function? Okay, now what I'm telling you there is no what if they're teaching Assistant class also has the function, print and inside the brain function I am writing teaching assistant. Okay, now what will happen? And let's say if I run this file, then the output will be student only because it is very clear here that we are that we want to call the print function a student class. Okay, so let's in this file. So that would produce trillion. No doubt. Now what if I removed the student Now, what will happen if I do a dot print? Will we get any other? Now that that's try to find out. So this is our teaching assistant class. So in the teaching assistant class, we have teacher and it inherits from student. So feature has a brain function. Student also has a brain function and teaching assistant has also has a print function. So what happens internally is when we write a door parent So what it will do. First off, all we will search in the teaching assistant class and the teaching assistant class has a function called print Since the teaching of this turn class has a function called print, So we will not to go to its parent glasses. Okay, we will not go to its parent classes, and this print function will be called and our output will be the Okay. Now what happens is in the earlier case, they're teaching assistant class doesn't have a brain function. So if the teaching assistant class doesn't have a print function, then we will go to its parent classes and both the parent classes as print function. That's why they will be an editor and beauty editor. Okay, so we're straight on this file and our output will be teaching assistant. Okay, So I don't put this teaching assistant now, just like the function. If we have multiple data members for the same name, then we will also get the error and that it will be like data member present in multiple based classes. For example, this teacher, the teacher class has a string name property. Let's see. Surrender also has the name property. Okay. No, we can see here seem name. Okay, now, if I have one toe, let's say I want to excess the name Data member. So a dot name is Let's say a B C D. Now, if I run this file, I will again get better and that it will be ambiguity at it. Okay, so we're getting an edit now. How to is all this error again? We have to specify the class name. I want to exist. The name Property of the teacher class. So eight or teacher School resolution Operator. OK, now let us on this file. So now our cold is working fine. OK? No other justifies everything. So we have discussed four types off inheritance, single, multilevel and hierarchal. All the three were very simple. The last one which was multiple. This was a little bit tough now. What happens in multiple is suppose you have three classes A, B and C And let's say you have a class D and lastly and added from all the classes classy, they asked me and classy. So this is the example of for multiple it is the example of for multiple inheritance, or is the problem with multiple inheritances? So if you ever did a member or function with the same name in multiple based classes, then they will be an editor. And how does all this error? So we have to specify the class names or D dart. First of all, the last name, then the school resolution operator and then the property name. Okay, so what is the problem with multiple inheritance? If more than one if more than one based class, whereas I remember with the same name of the function name, then there will be other ambiguity error, okay, and resolve this side. We have to specify the class name first and then the property name okay. And the second was, if the properties also present, suppose the properties also present being classically then their property, we will be exist. Okay, then There's no confusion. We can simply exist this property. Okay, Now there is also 1/5 type off inheritance, which is the hybrid inheritance vitriol discussed in the next radio. Okay, Thank you. 27. Hybrid Inheritance: Hello, everyone. So in the last radio we discussed about different types of inheritance. OK, In this video we will discuss about the fifth type. So in this would ever will discuss about the fifth type of finality ins, which is the hybrid inheritance. So what is the meaning of hybrid Hybrid means mix. Okay, So in order to achieve hybrid inheritance, what we will do, we will mix that four types of binary test that they were distributed. Let us take an example. So NPR do glasses, Let's say C in arid boot E N b. Now, at this time I am using multiple inanities. Now be in a really classy So I'm using my delivered inheritance here. And no, I am using hierarchal inheritance. Okay, let's take one more example. So suppose I have a classy now be NC Both class inherits from class. Okay, And now we have a classically which inherits from both class B and gassy. Okay, so what will happen here supports over the less structure off D gets a little less structure off. The structural fear would be very simple. It will have only a specific properties then, since being AIDS from classy it will have a some be specific properties. So this is B and the structural see will be some see specific properties and e So where do less structure? Roughly, The security will be very simple. So this is d they inherits from class BNC. So this is b being married from class A and B specific properties. Similarly, see sceneries from class A C specific properties and then we will have some d specific properties. Okay, Now, what will happen since Yasser D has two copies off glass. Okay. Classically has two copies off. Classy. So what it will do in future? It will create ambiguity How it will create. Mut. Suppose this classy has a print function inside public section. Okay, so what will happen here? We have a braid function, and similarly this a also aspirin function. Now, if you want to call print function that come by level, get confused. Which print function to call. Okay, so it will create ambiguity. No lettuce taken example. So suppose we have a vehicle class now Both the classes, car and drug they inherited from this worker class. Okay, so this is struck class. And now bus class inherits from both car and truck. Okay, so this type of structure, this is called our diamond problem and regret and beauty in future. So this diamond problem, it is a very well known problem. OK, so what will happen? So as we can see above. So this is also our diamond problem. So in diamond problem, we have ambiguity also, we have multiple copies. Okay, So due to multiple copies, we will have ambiguity. Okay, Now our a miss to avoid multiple copy every Mr avoid ambiguity. Okay, Now let's see in court how we can achieve the diamond problem and how we can result a diamond problem. OK, so let's say in court. So this is a record we have of the class. And inside that vehicle class, we have a default constructor. Ah, perimeters constructor. Ah, brain function and our district. Er Okay, so we have a class car which inherits from the vicar class. So we have a default constructor and our destructor. Ok, Similarly, we have a class struck. This also inherits from the vicar class and we have a constructor Now here comes glass bus It inherits from class truck and also it entered from class card and it also inherits from glass truck. And this is simple. A constructor. Okay, so now our damage problem is ready. And now let us first create the object off bus class. Okay? So must be now What will happen if I run this field worker with the order of the constructor call? Let us try to understand. So we have vehicle class boot the card in the class they inherited from the because last and similarly class bus inherits from car and truck. Okay, so I am creating an object. Busby. So what will happen? First of all, what was the order of the construct recall? So here we will write our order. So what will happen before? As soon as we create an object off bus B, we will go tocar tell us to call its to college constructor first by car class first because I have returned car first and then truck. Okay, so but we all know that before the bus class cause a terrible called its parent class construct herbal because since their two billions current truck, So first car class constructively record by car class because I've returned car first. So Carlos constructor were called. We will reach the car class and the parent of court losses Vehicle. So we will go here. And then the vicar's last constructively recalled it first. So first off, all week oclock and sectoral be called. Then we will reach tocar again Now the card last constructively recalled. Then we will reach the bus and then we will reach truck. So before calling their truck glass for glass constructed truck will call its parent class constructive itches vehicle. So now the regular constructive will be called. Then we will come back to Brooke. So now that class constructive will be called. And now, finally, the bus class constructor will be called. Okay, so this will be the order of the concept Miracle. Okay, so we can see here. The vicar class constructively were called twice. Okay, so let us try to verify our output. So let's send this file. So this is the order. So this is the order. First vehicle, then car, then again recalled. And truck and then bus. Okay, so do not look at the order of the Destructor. Why? Because we have no articulated destructor for every class. OK, but we know the order of destructive will be just the opposite off the order of the inheritance. Okay, so the order of destructor will be the opposite off this. Okay, Now you're Steuben moting. Let us try to call brain function. Okay, so be dart friend. So where's the brain function? So bus class doesn't have any print function? Brock doesn't have print function. Similarly, car doesn't different function actually attack sprint function. But we have commented out So vicar class as the print function. Since the print function is public, it is accessible toe every derived class. Okay, so B has access to the print function. So that means we will not get another due to accessibility. Blurred. See whether we will get in a red or not. So we will get We will definitely get an error and there will be due to ambiguity. So what is happening? What is the structure off bus class. So the structure of bus class is quite simple. So this is our best class. So bust class and at its from current Brooke. So this is card, and this is struck. So inside the car class, I have the classical and similarly truck class in AIDS from the class. So this vehicle class has brain function. And this week a glass is also hi sprint function Basically both the print function in exactly the same. Okay, So when we will run the file, we will get in a red line number 70 that brain function, its president and multiple based classes. Okay, they will be ambiguity. Problem. Okay. Compatible. Get confused. Which print function? To call all the board. The print function Exactly the same. But compiler will get confused. Ok, so now let's in this way to see So we are getting an error and that is due to end beauty. You can see that it also so print is ambiguous. Okay, now, how can we resolve this error? So there are two ways to resolve the seller. First way is to add ah, print function inside the bus class. Okay, So as soon as we will, as soon as we write a print function inside the bus class and beautiful, um will be result vital, basil, Because in the last session, because in the last radio we have seen that whenever whenever a class So in the last video we have seen that whenever a class, as a function off its own then first off all the we'll check the bus class only since the bus class has the print function, we will not go to its parent class. Okay, so there will be no ambiguity. So when I call this function PR print, this brain function will be called okay and are probably by bus. Okay, Solar. It's in this way. So our put this bus. Okay. Now, the another way to solve this problem is to specify the class. Okay, we will specify the class since both. So what is the structure? So let us right the structure here. Okay. So let us right the structure. So we have. So we have this class bus, this bus, glass and nights from God and from crook. And this is make a glass. So this is also vehicle This week, a glass has brain function. This we're good last altar esperan function. And now let us comment out the brain function of the bus class. Okay. No bus. Gus doesn't have any print function, So when I write, be dot print What will happen? Obviously we will get another because to print functions are already there. Okay, So to resolve this error, the second wave was to specify the class name. So either we have to specify the car or we have to specify the truck. We cannot specify the vehicle because both car and truck I zwickel, so it will not solve our ambiguity problem. So we have to specify a day, the card or either the truck. Okay, so it has specified the car. So we will write, be dark card and then scored resolution Operator. OK, so let's send this file. So now our POTUS vehicle. Okay, so our problem is result Now, what if no, but if I can comment the print function off the car colors. So what will happen now? Okay, So what happened is we have this class car. This class also has a brain function off its own. Now, what will happen if I died? So if I write, be dark car school resolution operator, print, what will happen? So when I write be dart card school Resolution operator, and then the print function. And if I rate be dot print. And if I right, we don't drug school resolution, operator and print. So what with our put off all these three lines. Okay, So first of all world output off this land. So first off, all this land will throw us enter via their because inside the bus function we do not have any print function. Since we do not have print function, we will go to its parent class, which is car and truck. And now they will be ambiguity. Why ambiguity? Because there are now three print functions. Okay, There are two separate functions now, so they will be m beauty. So obviously this will through a center. Okay, Now let's see this bead or guard school resolution, operator and print. Now what we will do it very clearly specifies Goto car class. And since the car class has sprint function off, it's one. So this print function will be called okay, And be dark trucks colorization operator print will happen. We will goto class class do not have print functional for its own. So it will go to its parent class parent class esperan function. So print. This time this print function will be called. Okay, so it will call this one and it will call this one. Okay, lets in this file, so But we're output now. This brain function will be called Khar Print function. Okay. Lets in this well so we can see here. Num tires, numb gears. Okay, so numb dies Numb gives and colors Sogard Brain function is being getting cold. Okay, now we have cleared them beauty. But still there is one big problem. OK, so what is the big problem? So ambiguities is old. No fuel, no ambiguities is all word day. Still, when? Very big problem that we need to handle. And the very big problem is that there are two copies. Class D will have two copies off glass. Okay, so this is glass tea and inside the class. Really? I have class B. Class B has a Aunt Emily. Classy has a Okay, so here we have two copies off glassy. Now we have to solve this problem. Okay? Ultimately, we want only one copy. We're only one copy off. Classy. OK, so we have to avoid this copping. How can you afford this? Copping we can use the keyword. Virtual. Okay, so there is a keyword. Virtual. Now let's see where we have to write virtual to solve this copy problem. So glass car before writing the public, we were right virtual And similarly for truck class we have to write virtual Okay, now what this virtual will do So this virtual will ensure that classically will now have only one copy of class A Okay, so let's commend this out. So now we are creating an object off bus Be So if I will run this file work with the order of the construct recall Let us try to understand. So I have this working class then car and broke So car classes and everything Classical But we have a keyword Virtual Okay, we are generating the cast but we have giver virtual So what virtual will do? Let's try to understand And we have bus here. Okay, so see Busby So what will happen? So first of all what the best class will do It will go to its bear in class to call it default constructor. So we'll reach car class since the car class is virtually inheriting from the vicar class. So what will happen? Bust class will call the vehicle class bus class will call the constructor their default constructor of difficult class So the order of the the Order of the Constructive call will be first. This vicar has constructively been called. And who will call bus class? Constructive will be called This cannot call for a car. Inter cannot call because they are inheriting the vicar class virtually so they cannot call the constructor. Okay, so first it will be a coid The credulous constructive will be called then car class and then class. And then finally the bus class construct a biblical so as we can see here because last construct level because we live ones. Okay. And who will call bus will call neither car nor drug. Okay, so let's let's see the knowledge on this file. So, as you can see, first recalled car, truck and then bus. Okay, so we cook us construct place called only once, not twice earlier. It was called twice. Okay, but here it will be Call only once. And who will call? Bus class will call. Okay, so what is the concept of a virtual base class? Okay, so how virtual is helping here? What is the purpose off Like, what is the meaning off this virtual based class? Okay, so earlier What was happening. This Guardia's has object has object off virtual class. So this was really a situation before using the virtual keyword Now we are using were actually So if we could classes now are virtual based class. So what will happen now? So this is car class. This is a class. So I lay the car Notre class. They have the actual vehicle object, but now they will have a pointer. Similarly, Truck will have a pointer to the vehicle object. They now have a pointer to difficult object earlier. They have difficult object. But now they have a pointer to do vehicle object, okay and right of the structure of the bus so earlier bus only his car and truck object. But now bus will have vehicle object. It will have car object and it will have broke Object. So that's why bus will call the vicar's last constructor nor car neither car, neither truck. Okay, so bus will be able to call the working class constructor, vicar class constructor and car and truck cannot call the vicar class constructor because they only have pointed and not the actual object. Okay, so now we are awaiting a copy Okay, so now we are awaiting Copy. We only have one copy. There are not a multiple copies. Okay, Now, let's even more thing, OK, Okay. So no lettuce coming out, the constructed their default. Construct off calculus. Now, what will happen? Okay, so since we have paramour ties, constructor So their default construct off record classes not visible to us. Okay, So what will happen? So now we have to call the paramedics. Constructor. Okay, so sinister. Defile. Constructive. Bigger classes not visible. So now we have to call this Paramount praised constructor explicitly, Because implicitly a child class can only call that the file constructor off its parent class. Okay, so if you will run this file Busby, let's in this file. So we are getting another and let's see that. What is that? It So the other is So batter is broke, but and God, So we're getting another in all the three classes car, bus, and very struck. So this is struck. Okay, so we are getting an error in all the three classes. So what is happening here is so in the last three videos, I told you that a class can only call the constructor off its immediate didn't. But here the bus class is calling construct. Perfect. Grand bidden. Okay, so this is a special keys. Okay? I'm repeating myself in their level. Does I told you that the class can only call the concert profits immediate parent, but here, the bus class is calling the construct profits grand parent. OK, but only in this case because we're using the virtual keyword. Okay, we're making the vicar classes virtual base class. Okay, so only in this case, glass can call the constructor off its grand parent. Okay, so this type of inheritance is also known as virtual inheritance. Okay, so this type of a night dances, alternatives, virtually inheritance. Now let's solve this problem. So how can we solve this problem since we don't have any default? Constructor, we have to call parameters constructor. Explicitly. So glass card. So with the help of initialization list, we can Let's say three. Okay, so let's spend the value of their here, so I'm bringing the value of that also. Okay, Now, why am printing the values that you will understand in some time? So, Brooke vehicle and let's say the values for we are calling the paramilitaries construct Tarok. And similarly, we have to do for bustle toe because but also has the object off vehicle class. Okay, This is a special case, Vera. We're a class can call the concept of its grandparent. Okay? And let's say the value is and let's see, the value is five. OK, sure. Value tree value for value four and very five. OK, and I'm printing the valley off dessert here. Okay, lets in this file so you can see what is the value getting printed? Five. This is the proof. Very abused. Five. Here. Okay, so here we're using five. So this is the proof. Okay, So we have proved that bus glasses calling the because last constructor and not the car in the truck. Okay, So I hope now you understand what this diamond problem and how we can use virtual keyboard and how to resolve them beauty and how to avoid copy. Okay. Thank you. 28. Polymorphism Compile Time: Hello, everyone. So till now we have discussed in detail about inheritance. I hope that part is now clear. Now in this video, I want to discuss next topic off. Oops Lettuce polymorphism. So polymorphism means many forms. Okay, so in terms off court, we can say polymorphism means we're assert of course, be of differently in different situation. Okay, so there are two types of polymorphism So 1st 1 is the compile time polymorphism and the 2nd 1 is rent time Polymorphism So combined time Polymorphism means how assert off court will behave How's it? Of course will behave well we decided at the compile time Okay And anti polymorphism How the sort of course will behave will be decided at the current time. Okay, so in this video our focus is on compiled time polymorphism and the next radio we will cover in Temple Muff is a Maysville. Okay, so compile time polymorphism toe compile time polymorphism can be achieved using movies So the first way to achieve compiled them Polymorphism is functions overloading which we have already structured And the second way to achieve compiled them Polymorphism is operator overloading which we have also started in hopes into deals. Okay, so what is the meaning? Off functional Lording. So it means that different functions with the same name but destructive will be different. Okay, so we will have many functions. We will have many functions. Those function will have the same name. But destructive will be different. Okay, so let's see in court. Okay, so I have discord. So as we can see here, we have many functions with the same name based function, test function, destruction All the three functions have the same name. But the number of arguments are different. So if I will call faced then it will call dysfunction because the number off arguments are zero. If I will write best win, then this function will be called okay because of the number of arguments. So we are deciding at the combine time which function will be called. Okay, so we're deciding at the combine them Which function will be called. That's where we can use function overloading to achieve compile time polymorphism. Okay, So what will happen if I create one more function? Suppose I have these three functions and now I am creating one more function. They don't ever the function is void. And the function name is Seamus. Test. Okay, The function name is best and we also have a function in protest. So among these two functions, only the return type is different. Here, that anti percentage and Heatherton type is void. Everything is same. Okay, Same function, name and the number of arguments are zero. Okay, we're not receiving any argument. So one thing that I want to tell here is we cannot differentiate between these two. Function with the help of return type. Okay. Return type with the help. Overturn type. We cannot differentiate between these two functions. Okay, If I will call from the mean test when the compatible get confused, which function to call this one our this one. Okay, so they will be ambiguous together. Compiler will get confused among these two functions. So these two functions cannot be created in one file. Okay. We cannot differentiate with help off return type. If you want to differentiate. If you want to differentiate, then with the help off functioning, we can differentiate with the help of function. Name the number off arguments and the type of arguments, but not with the return type. Okay, Now, No, we have already know where. Dysfunctional lording. Now let's see what this operator or lording. So if you remember, we have discussed about Obrador lording in detail in Ove section on Lee. OK, so let's take the example of plus Operator OK, so let's take the example of plus Operator So when I raid two plus three, output will be five. So here, plus adds to in teacher when I write 3.5 plus let's say 1.5 and output will be 5.0. So plus operator adds to the bells here. If I had, I'd corrector a place character be then work plus operator will loom. It will convert these two values into its ask I value. So this will be 97 this will be 98. So plus adds two characters here. So we have only one operator, which is the press operator and plus operatives behaving the friendly in different situation. OK, if you remember the complex number class, we have overloaded the plus operator for complex number class. Then if I write seven plus u two, then here the place operator is working differently. Okay, so we are deciding at the compile time. Only that how the operator will work. OK, so with the help of a patrol lording we can achieve compile time Polymorphism. Okay, so I hope these to work Very clear. How were Children compiled them? Barbarism. We are deciding at the compile time. Only that word assert off court will do. Okay, now date is a 30. There's a terribly also to achieve the combined type polymorphism and it is called Method Operating or we can say function of rating. Okay, matador function. Overeating. Now let us try to understand what is the meaning or function Overrating. Okay. No. Okay, So what is functional writing? So let's say I have two classes class and class B B inherits class and so is the parent class and parent Orbis Class and Beastie Child Or drive the class. Okay, Now suppose glass has a brain function and we have also created a print function inside class B. We also aspirin function off its own. So what? It will help. So what will happen? This print function will override this print function. Okay, Now let us understand with the help of court. Okay, So I have this class so I have a classical and I have a class car. So inside the classical I have a brain function and inside the car class. So car class first awful. It inherits from weekly class and it is and it is also having a brain function. Okay, so what will happen? This print function will override the sprint function. Now what I want to convey here is, let's say we are creating objects, so I am creating object off vehicle class. And let's say I am also creating the object off car class. Okay, so overtly with the order of the constructor call. So we have already discussed about the order of construct Trickle. But let's say let's revise it again. Let's recap. So in this case, what will happen Onley the vehicle class construct it will be called and in this case, first the vehicles less constructive will be called. And then the car class construct people we called. Okay, so what is the structure off? Because glass. So this is simple vehicle class and inside, and it's anodized brain function. So this is car class and it has Vicky class. It has brain function and the car glass also has brain function off its own. Okay, So now if I run this file, what will happen first of all, with a class constructor will be called. And in this case, first weekly class and then card last constructor. But I have not created any constructor, so we will not be able to see the messages. Okay, now, what will happen if I call the print function? So if I write, we don't print And if I write c door print, then we're do think what will happen. So we already know we don't print it will call the print function off the vehicle class. So the output will be vehicle. And if I call Sydor print what will happen? It will call the print function off the car class. Okay, so the output will be God. Okay, So we are deciding at the compile time, which function to be called. Okay, I'm repeating myself. We are deciding at the compile time or leader, which function will be called if we have multiple options available to us. So in this case, I have multiple options available to us. I have to print functions, so I'm deciding at the combine them or later. This sprint function will be called Now how I'm able to decided the combined them because we can see here this week. It belongs to vehicle object. This is a vehicle object. So when I read the adornment, it will call the print function off the vehicle class. Now here I am, writing seed or paint now see is an object off car class, so it will call the print function off the car class. So that's where the sprint function will be called. So with the help off type of object, we can decide which function will be called. Okay, now let's win this fight. Okay, so first of all, let's right. We don't print and see department. Now let's and this file So that would produce vehicle and God read or print and seed or print. Now, if the car doesn't have any print function, then we will call. Okay, so what I want to say it is if I do not have, let's see the cartel us do not have print function if it's on so you know what will happen . So if the car doesn't have print function off its own, then we will call the print function off the vicar class. Okay? And if because class doesn't have print functional, so then it will through it. Okay, so this language through a center if the vehicle doesn't have print function, Okay, Now let's take one more example. Okay, Now here we are, creating the objects aesthetically. Now, what will happen if I create the object dynamically? So, Victor Star V, let's say V even because he has really been greater. Now this is new vehicle. Okay, so what will happen now? So what is happening here? Is that this lane? What will happen? So this is even and this even points to a vehicle object. So this is a vehicle object. And this is a vehicle point or even a cervical pointer. Size will be eight bites. Okay, now what if I create another object? Let's say I'm creating. But if I were right because start, we do. Okay. So what will happen? So of you two pointer of ical point, it will be created, and it will point toe a random garbage location. Okay. And if you want to initialize if you want to initial s this vehicle pointer, then we can point it towards an ethical OK, what I want to say it is Let's say I am creating one more vehicle we call Pointer. Now this vehicle pointer is not pointing towards a vehicular disappointing towards a random garbage location. And if you want to initial s this point that we can point it towards an ethical for example , we can write We do is we do is containing the address off. We basically were too is pointing towards Okay, So what will happen when I rate we do is so when I rate we do is pointing towards river So what do you do? Is the pointer and we witnessed the Jellicle object So we do is pointing towards even okay we can also So what we can also do here is so let's come into doubt. So we two is a vehicle pointer But we can also do something like this. We do now points toward the car class object. Okay, we do is pointing towards the car class subject. So this is my God bless subject. See the name Isi and this is vehicle and this is the brain function. This is the brain function. Okay, so what I did here is we're two is now pointing towards the car class subject. Okay, so this now, this will be the scenario. Okay, so it is pointing towards the car class subject, So we two is a beast class pointer. So this is a base class pointer and see this is derived class. Object. Okay, so derived the class object. So what I want to say here is a beast class pointer can point The words are derived that subject. But the vice ever says not true. OK, so when I write, we do is pointing toward see So what is the meaning? So based class pointer can point. So it's child glass object, but the vice versa is not allowed. OK, now I'm explaining the whole court again. Okay, So what is the scenario? Okay, so we could be first of all this language, Calvi. So what is the scenario? Let's say this is a vehicle view object. This has brain function on. Let's say it's address is 200. Okay, now Karsi. So it in ads from the week a glass of this is see object. This is V. This is the brain function, and this is the brain function. Okay? And led Sylar. This is 400. We don't paint cedar Point. Then I'm creating. And then I'm creating the object dynamically. Okay, so this is this is V even. And this is my dynamic object. This is vehicle object. Okay, This vehicle object has print function. And let's say it said this is 100. So even contains hindered, and it is pointing. Okay, It is pointing towards this dynamic object. Then I created another van Wyk object. So it is not a dynamic object. Disappointed only Okay, Because last pointer. So let's see, the name is Vito and then veto is pointing towards that derived class object. So basically it's address is 400 so it will contain for rendered and this is the scenario. Okay, so this is the compute scenario. Know what will happen if I try? And if I tried toe right this school view Tuero print. Okay, so what'll without foot? So when I write v Tuero print so we have two options. Either the sprint function will be called or the sprint function will be called Now what will happen So if I will write even not bent, then it is very simple. So even a rope print, then it is very simple. We only have one option that does the sprint function. Okay, so the sprint function will get cold. But here we Tuero print. We have two options this sprint and this print and why It is a scenario because a base class point is pointing towards are derived class object. So which print function will be called? Okay, so what do think Which print function will be called? So one thing that is important here, whenever we do something like this will do, is and percent off, See? So what happened is when ever do something like this, this means so with the help of veto, we can only access those properties that are present in the base class. Okay, all go over to is a beast class point, and it is pointing towards are derived class object. But with the help of veto, we can only access those properties that are present in the base class. So that means this print function will be called. Okay, so this pain function will be called always remember this. Okay, make it a point. Ah, based class pointer whenever a base class point is pointing towards the drive class object . And if you're using we to it to excess something, then we can access only those property state are present in the base class. Okay, now let's in this file. Okay? So let's coming out. This one and this one. So the what we're doing here is I'm calling the brain function through. You do? Okay, so I'm writing here on wood. We can only access base class properties, properties that are present in the base class. Okay, so that's way the output off this line will be this print functional. Get calls with output. Will be vehicle. Okay, let's on our file. Okay, so this is trying is headed. Okay, So the mistake is spelling mistake and similarly waited a spelling mistake. Okay, so now it is correct. So that would put this vehicle okay. So we can only exist on little we can access only those for a petitioner. That president in the base class. Okay, now, here it is. The example over compiled time polymorphism. Now why? It is an example of compiled i polymorphism. So basically which function will be called were taking their decision at the compile time only. Okay, so I'm repeating myself. So when we right view Tuero print. So this is an example of compile time? Well, a formalism now why? It is an example of compile time problem of them because we are deciding at the compile time which function will be called. So we have two choices for the print function. First it the car class print function and the second is that vehicle class print function. So, Vito, first of all, I don't care to whom we twist pointing. So we do is pointing towards the car class the carcass derived. Basically, they're derived object, But I don't care. Okay, so I don't care to whom we twist pointing since Vito is a type of vehicle, so I will call on leave recall print function blandly. Okay, I will call you to print, function, vehicle, print function blindly. So we're deciding at the compile time only which function will because that's right. This is an example of combines Ban polymorphism. Okay. Thank you. 29. Polymorphism Run TIme: Hello, everyone. So in the last video, we started discussing about polymorphism. So we have discussed about compiled time Polymorphism. Now let's discuss about renting Polymorphism. So what is the meaning offer and damn polymorphism? So it means that I will take the decision at Runtime. Okay, What operations you want to perform will be decided at that time. So in the last video, we did something like this. So in the last radio video, something like this We created a vehicle pointer and then the vehicle pointer was pointing towards the drive class object so we can write like this also. So vehicle start of you too. This is new card. Okay, So beast class pointer is pointing towards a car glass object. Okay. And when we did something like this when we are calling the print function, then what will happen? So the car and vehicle both have print functions. So when I'm writing you to a rope print so the culprit function will be called Why the culprit function? Because true we do. We can only call the properties through. We do. We can only exist those properties that are present in vehicle class. Okay, so why the vehicle Print function will be called because we are deciding at the compile time only that this veto is an object off type vehicle sensitizes off type vehicle. That's why we will call the vehicle print function. Okay, now what I want is I want to take decision a different time. Okay, So I want when I write we Tuero print then in stewed off the culprit function car class print function should be called. Okay, Why? Card class? Because we do is pointing towards ah, car class subject. Okay, so you do is pointing towards a car class subject. That's why I want that when I read with Duero print car class brain function should be called. Okay, now this is runtime polymorphism because I want to take decision it rent pain. Okay. Now, to achieve their in temple move is, um we need to take help off virtual functions. Okay, so first of all, let us straight on the strand worked our virtual functions. Okay, so our goal is very simple, but is have a goal. I want when I write, we duero print then stewed off the culprit function. I want to call the print function off the car class. Okay. And by the print function of car class, because we, too, is pointing towards a car class object. Okay. Now, to achieve this Vinnie in her in 10 polymorphism and to achieve their intent Polymorphism, we need to take help off virtual functions. So now let us discuss about now. Let us discuss what are virtual functions. So virtual functions are do its functions that are present in the base class, and that has been overdone in the derive the class. Okay, so these function will be present in the base class, and then we will override those function and did drive the class. Okay, So how to make a function? A virtual function. So in order to make a function of virtual function, we need to write the Cheever virtual. Okay, so where do we go? I want to make this print function as a virtual function, so I have to write the Cheever virtual. Okay, So now dysfunction is a virtual function. Why? Because I have returned the keeper Virtual. And also this function has been over it in in their derived class. Okay, So what is the meaning? What we will achieve by writing the keyword virtual Okay, so the virtual keyword with the help of Virtual Keeper, I am telling the compiler to take the decision at runtime. Okay, I will tell the come by little take the theater in time that which print function to be called. Okay, so what will happen? It there in time I will go and check which type of object of you two points to. Okay, So I during time when I when I am writing the statement So when the compiler will reach here what will happen at the runtime compiler will go and check what type off What type of object of you two points to So we two points to this car class object Since you two point socar class subject than car class print function will be called Okay, now why? I am taking this mission veteran time Because I have returned the keyboard virtual And also dysfunction has been over it in in the car class. Okay, in there derived class Now when I will run this well what will happen? This car class brain function will be called Okay, so let's in the fight so we can see here that would put this card okay, so I'm repeating myself again. So what will happen at the end time? I will go and check what this we do. Object points toe. If it is pointing toe a car class, then car class print function Well, because every disappointing tow a vehicle class, then vehicle class brain function will be called. Okay, now, let's see one more example. Now, what will happen if I if I will remove the brain function of the car class? Okay, So what will happen, but without put off this line, we Tuero print. Okay, so let's another file said our protests coming out. Toby vehicle. Okay, Okay. So that would produce coming out of the vehicle now that the straight or in distant. So when I write V two era print now, which brain function will be called? So we do is off type vehicle, but since I have written virtual in the base class, so I have to take the decision, It runtime. So we will check at Darren time. So this is card. This is We call this a sprint function and this is the print function of the car. So we two is pointing towards a car class object. So this time this print function will be called. Okay, now, when I will remove the print function from the car class, then what will happen again? I will check whether the car class has a print function. No, it doesn't have. So I will go to its parent class. It's been in the glass esperan function. So this time this sprint functional difficult class will be called okay. And output will be vehicle. If the vehicles last doesn't have print function than this land will through its added. Okay, Now, what will happen if I commend the print function of difficult? Okay, now let's so we have brain function inside the car class, but we do not have print function for the vehicle class. Okay, So if I will run this file, what will be our output? I think we will get another. Okay, Now let us try to understand why. So we are getting an edit, and if you will see that it so classical, no named print. Okay, So what it is saying here is we do not have print function inside the vehicle class, OK? We don't have print functions had the vehicle class. And we all know we can only access Those from pretty straight are present in the vehicle class through view too. Okay, I'm repeating myself. We can only access those properties through veto that our president in living color, class and vehicle class doesn't have any brain function. Okay, so in this way, with the help of virtual function, we can achieve rent time. Polymorphism. Okay, now let us try toe. Now let's discuss about the use case off virtual function. Why? We will need virtual function and why we need in time. Polymorphism. Okay, so suppose we have organization in organization. We have different type off employees and what we want is we want to color the salaries off employer at the end of the month. And the formula for calculating the salaries for different employ is different. Okay, so suppose we have four type of employees. We have a job. We have managers, we have engineers. And at this. Okay, so we have four types off employees and we want to calculate the salary for all the four employees. And the celery formula is different for different employees. Okay, So how we can solve this problem. So what we will do? Let's see. I will make a class employees, OK. All the same features all the common features of the four employees. It will be present in the employee class. Then we will create four classes HR manager Ingenious. And at this. Okay, so we will use in evidence here. Okay, so HR manager ingenious. And there they will inherit from the employee class. Okay, so we're using inheritance here and all the common features off the employees are present and employ class. Okay, Now I have a calculator to celery function. Okay, so I have a function calculated celery. Okay. So each class will have dysfunction. HR will have conclude. Celery function manager will also have covered celery function, ingenious and others. Okay, so all the four classes will have this function. Okay, So, Calvert, Sally function is a virtual information is a common function. Okay, Now let's say I have one managing the company in the organization. Let's say we have We have one nature and we have three managers. Let's see, we have 20 ingenious and that the staff is let's say food. So in total, we have 28 employees. Okay. Now, what will you do? We will create area of pointers. Okay, so what? I will write. So we will. Right? I want to create any of pointers. So employ. That was start. Let's in. Name is E. This is new employees star and granted. Okay, if I turned eight because we have turned eight employees. Okay, so this is a off pointers. Okay, so we have at AOL size 20 it. So this is Seattle. When do tree and so on. So we know that the base class pointer can point toe a child class object. Okay, so this is an area of pointer and the base class pointer can point to a child glass object , so they index zero. It will point to HR class subject. Okay, Index one, It will point toe a manager class object, simply manager and manager, and then we will have ingenious and finally others. Okay, so why it is so because Because we know that the base class point that can point towards a child glass object. Okay, so they index zero is pointing towards attack. Last subject index one is pointing towards manager, class, object and so on. Okay, now I want to calculate the salary. So for calculating necessarily what we will do, we will run a loop over this area. Okay, we will gonna loop or disarray. And inside the loop what I will write I will write something like this. E a Addo, calculate celery. I will call this function. Yeah, you know, girl cleared celery. So we will right inside the loop e a local world Celery. Okay. Now suppose this employee class It also has a colored celery function. So this employee class also has ah calculate celery function and that function is a virtual function. Okay, The car virtually function inside the employee classes. A virtual function. So when I will write the statement Tierra, Culvert, Celery, what will happen? We will take the decision at the right time that which function will be called Okay, since we have returned will chill here and all the four classes and all the four classes have covered celery function. So at this land, what will happen? We will take the decision at runtime that which calculates celery function. We have to call okay. So at their in time, what will happen which function to be called it will depend upon the type of the object. Okay, so afford Index zero for index zero. What will happen? So Index zero is pointing towards a shark. Last object. Okay, so for indexes, you don't charge it. Calculate. Celery function will be called for index one. Manager calculate celery function will be called and so on. Okay, So which function will be called? We will decide it there in time. So it depends upon the type of the object which is present at the IAEA. TENDEX. Okay, so the Iet and legs, it will decide which print function will be called. Okay, so I hope the use case off virtual function and different pain polymorphism is now clear. Okay. Thank you. 30. Virtual function and Abstract class: Hello, everyone. So we have discussed about polymorphism in the last two videos. I hope that is clear now. And we have also started discussing about virtual functions. So what are virtual functions? So virtual functions are those functions that are present in the base class and they're over it and in their derived classes. Okay, In this video, I want to discuss about your virtual functions. Okay. I want to discuss about your virtual functions. So what are your virtual functions? So your virtual functions are virtual functions, but they do not have definitions. Okay, so the functions that do not have definition are called pure ritual function. So what is this index for creating a function virtual. So we write the Cheever virtual. And let's say we are talking about the print function off difficult class. So by writing the key word by hiding the Cheever virtual, the sprint function is now a virtual function. Okay, now, this is a normal virtual function. I want to create a pure virtual function. So that's intakes for creating a pure ritual function is first rifle. We will write the keyword virtual. Then let's say I'm converting this function into pure which will function so well chilled white print and your ritual function means they do not have definition, so it will not have definition. So this is the Centex for creating a pure virtual function. Okay, it will not have definition. Now let us see in cold. Okay, Now leads and come in this part. So I want to create. I want to convert this function and to pure Rachel function. So we have to remove their definition. I am leaving the definition and then we do not have definition. Okay, so this is pure virtual function. No. Okay, So this is the Syntex or creating a pure ritual function simply no definition at all. Okay, now we will see in sometime. Why we need your virtual function. What is the use case off your virtual function? But before your Rachel function, let us talk about abstract classes. Okay? What? I have said classes and why do we need them? So let us first try to understand. We're not have strict glasses. Okay? So if a class contain a pure virtual function, then that class is an extra class. Okay, So if a class contains a pure virtual function, then that class will become abstract loss. So here vehicle is an extra class because it is containing a pure which will function. Okay, Simple. Now, what is the meaning? Off abstract. So if stricter means incomplete. Okay, so this vehicle class is an incomplete class. White is incomplete because it is having a function. It contains a function that doesn't have definition. Okay, now, what is the purpose off after classes? So if a class is an extra class, then if you will try to create the object off the extra class, then you will get another. Okay, so basically, we cannot create object off FC classes. Okay, since vehicle is an extra class, so if you will try to create the object of difficult class, you will get another. Okay, so if you will, right, we cull V, you will get an error and there will be that vehicle class is an extra class, so you cannot create the object of the FC classes. Okay, now, let's see in court. So let us commend everything. Okay, so we have only vehicle be ok now that the straight on this file so that output will be that vehicle class. We will get an error and there will be. So let's see that it So that is vicar classes an extra class. And we cannot create the object of the F sec classes. Okay, simple enough. Now there is one more thing that will happen since so this is we could class. And we have a class car which, united from the vehicle class with class, has now become an extra class because it contains a pure virtual function. Okay, now class, God has two options. Glass God has two options. First option is that it will implement all the pure ritual function off the vehicle class. So implement all the pure virtual functions off difficult gas. All your virtual functions off because less Okay, not a second way. The second option is it will not implement all pure virtual function. So what will happen? This glass car will become extinct. Us. It will also become stateless. Okay, so Laskhar has two options. First, first option is implement all the pure virtual function of difficult class. Then in that case, the class car will become a normal class and then we can create the objects of the car class. The second option is if it will not implement all the pure virtual function. If it will not give the definition off or purely virtual function, then in that case, it will become and have sex class. Okay. And we will not be able to create the objects off the carcass. Okay, so in this case, we can see here brain function is a pure virtual function, and the class car is giving the definition off. You're Rachel function all the pure ritual function difficult class. So in this case, this is a normal class. This is right. But if you will remove the print if you'll remove the implementation of the brain function , then the car seyval through a center by because it always also become NFC class incumbent class. Why? It has become an extra class. Because if you will see the structure of the car class, you can see very carefully that this is a glass car. Since this class car inherits from the vicar class and weaker class has, ah, function has a in compared function. So the class card also has this incomplete function. Okay, this glass card also asked this in compared function the car class is an extract last also , So we cannot create the object of the car class. Okay, now, let's see in court. So Okay, so let's remove the definition since, Okay, so first we have definition. Since we have definition, we can create the objects of the car class. Okay, So if you will, right, Garci, then this is right. Okay, So have a cord will be working south. Accord is working. Okay, Now, if I will remove this brain function So this car class has also become NFC class, and this time it will run. This way, we will get another. Okay, so we are getting an edit and let's see better. So the class car is an extra class. Okay. Okay. So now we have understood what are pure virtual functions and what I have strict classes. Okay, So one more thing. What are pure after classes? Okay, so there is something called the order of strict classes. So we know what that after class, there is something called if your abstract glasses, what are people have strict classes. So since the vehicle vehicle is a pure after class, because it has only one function, and that function is a pure function. Your virtual function. Okay, So pure after class means if any of strict class has all the functions as pure ritual function. So oil functions will be pure virtual. Then their class will be your FC class. Okay, so this vehicle Okay, so we have this record class this record class can have many functions. Okay, lets a brain function and let's get the sense centers. Okay, so this brain function is a virtual your virtual function. Okay, so this this is a pure virtual function Varies. Get trendsetter. They have definitions, so they are not your virtual function. For in that case, this record class is only abstract class. We will call this class only if strict class via strict, because it is containing a pure virtual function. But if the gators and the centers, they are also pure virtual Okay, If I will make if I will remove the definition of getter and setter, I make them zero Then this vicar class is containing all the functions as pure virtual functions. Then this abstract last will be called less your extra class. Okay, so perhaps sick last means all the function of the class will be pure. Virtual. Okay, simple enough. Now we haven't destroyed the meaning off extra classes and the pure virtual function. Now let us see the use case. Let's discuss about the use case. So in the last video we discussed, we took an example off an employee an organization which want toe give celery to the people and the seller form. Every were different. So they were four employees HR, manager en genius and others. Okay. And what we did was we created and employ our e. So this was off type employee star. This is often employ style. So the first index zero was pointing towards an object off HR class, then manager and then ingenious and others. Okay. And then we realized it over this area, and then we did then inside the loop videos. Something like this. Yea l o calculate celery function. Okay, we are calling the calculate celery function, but with the help off e, we can only access. We can only access the properties off the employees class. That is the base class. We can only access the properties of the employees, close only the base class. So that's why we have to create a calculate celery function inside the employee class. And that function was virtually okay. Why were killed? Because we have to decide at the wrong time that which function to be called. Okay, So everything was working fine. Okay, so we cared it. God's word seller function in inside the employee class and their function was virtual function. Okay, so everything was fine, But I won't do what I want to say. Here is now this calculate celery function should be a pure virtual function. Not only virtual, it should be pure virtual. Okay, Why pure virtual? Because I cannot decide what will be the celery inside the employee class. How can I give the definition of calculus celery function? Okay, I cannot get the definition of Colcord celery function. Okay, So since I cannot give the definition but I will do, I will make this function as pure virtual function. Okay, Since dysfunction has become the pure ritual function, we cannot create Arco object off type employ. Okay. We can create way have to rule. We have to create a new class if you want. Oh, add another member. Okay, let's it any remember new stuff or something? Okay, So this is the use case off your virtual function. There is one more use case. For example, if you want to force a child class to implement a function. Okay, So what do you want to do? I have a child glass and I wandered child class. I have a child class and I've wandered child class to implement a particular function. I want to force the child class to implement a particular function. What? I will do so inside the inside the beast class, I will make this function as pure virtual function. Okay, so that the child class will be enforced to implement their definition of the spiritual function. Otherwise, the child class will become the abstract loss. Okay, so you can take one more example off how the pure ritual function can be used. For example, I have any animal class and inside the animal, we have like a tiger cow whose exacta So this animal class has a function that's a huge function. Okay. And the Tiger co. And whose Okay, they will have their youth function. So what we can do? We can make this you function as pure virtual okay, because it cannot give the definition off. You function inside the animals loss. So we will make this you function as pure ritual function in this way, that tiger class, it will have it on its function. It will give the definition offered. So honored function call will give the definition off. Its only function and holds will give the definition offer its only function. Okay, so this is the use case off your virtual function. Okay, So I hope everything is clear. No, thank you. 31. Friend function & Friend class: Hello, everyone. So in this video, I want to discuss about friend functions. Okay, so let us take an example. Suppose I have a class struck now inside the class truck. I have some private publican protected properties so private, protected and public. Okay, so let's see. Exeter, private property. Why is a predicted property and there is a public property? Okay, so the private property X, it is not accessible outside the truck. Plus, OK, Similarly, the protector property. Why? It is accessible, outsider per class, but only with the help of derived classes and said this property is open to all. We can access it anywhere. Okay, now, suppose I have a glass bus now the bus class has a print function. Okay? And this sprint function, it wants to excess the private property off the truck. Lesok it want to access the X. Okay, So how can this print function can access the private property? Often Ridiculous. Okay, so the answer is with help off friend functions. Okay, So with the help off friend functions Ah, Class A class can access the private and the protected properties off the other class. Okay, So, with the help of friend functions are class can access the private in the predicted property of the class because the public properties already accessible to everyone. Okay, so what we have to do? So what we have to do? We have to make this sprint function. Ah, friend off this class. Okay? Now we all know friends knows it all. Okay? I want to access the secret off truck so different has to become the friend. Okay, on different knows the secret. So when the brain function will become the friend off the truck loss, it can exist. The secret property. It can access all the secrets off the truck class. Okay. In order to see in cold. Okay, so I have a glass truck now inside the class struck. We have decided that I have some have some private property. I have some predicted. Robert E and I will have some public property. Okay, now I have a class bus. Glass bus has a function took last bus has a function. Now what dysfunction wants? This function wants to exist. Access the X off truck. This function wants to exist. The private and the public properties private and the protectorate properties off the truck class. Okay, so how can we do this? So the only ways what you will do, we will declare this print function as a friend off the truck class. Okay, So what is this? Index sensex is way too simple. First of all, we have to write friend. Then we have to write void, then bus school resolution Operator. The name of the function print. Okay, so what will happen now? Okay, so now the print function off the bus class is now a friend off the trackless. Okay, The print function off the bus class is now a friend off the truck class. So the sprint function now can access all the secrets off the trackless. OK, but if he will run this file, we re gettin ahead. Okay? The arable be at this line. Let's send off. I Okay. Okay. So what is the added? Okay, so this will be is there Okay, so it will. In this way, we will get an error at this line. So what is that? Our other is at this lane. Compiler doesn't over. Tis bus. Okay, if you can. If you will see that So bus has not been declared. So what happened in C plus plus? Okay, so we are getting a compilation ever at this lane. So what happens in C plus plus, So in surplus, best execution starts from demean. But the compilation start from the very first line. Okay, Said the compile a shin will be from top to bottom. So at this line, line number 12 we do not have bus. Okay, But it's not declared so. Come by level north. Go. Red light number 15. It will not search at this land. The combined it will stop and it will tell us that he doesn't know what this bus. Okay, so what we have to do, we have to declare We have to write this court in front off before the class, Okay, above the track class. So let's move the whole court. Okay, so let's in this file. So at this time, we're not getting any other. Okay, now, one more thing that we have to we have to be careful. So now dysfunction is a friend off the truck last, So we cannot give the definition here, OK? We cannot give the definition. We have to give the definition outside the class. Okay, so I am giving the definition here, so forgiving the definition. The structure will be void. Bus score resolution Operator, Print. Okay, so now in this function, so no head within this function, I can access all the secrets of the class private and protected properties. Okay, X y insert all are accessible. Okay, So for accessing their private properties and the protected properties first awfully will create an object. So Bhakti so I can exist x 30 existence I can access way. So do not why is let's say 20 and let us also print the value of X and y soc out did our X and did Ordway. Okay, Now let us call this function brain function. So I'm creating an object, Busby and we will call the function be dot print. Okay, now let's in this way. So that would produce coming out to a 10 and 20. Okay, so I record is working Fine. So I record is working. Fine. Okay, so let's do one more thing. Suppose I have a global function. Okay, so I have a normal global function. Let's sit anywhere. The function is best. Okay, Now, this best function this test function also wants to excess the private and the protected This struck. It also wants to access the private property of the truck class. Okay, so what we have to do, we will do the same thing. We will make this test function as the friend off the truck class. Okay, so it's index will be quite simple. We were right friend, then void and then pissed. Okay. So again, if you will, in this way, we will get the compile ation error at this lane. Because this test function does not belong to track class because we have return friend and before the test function. So this dysfunction doesn't belong to distract class. And when we will reach line number 18 we will get compilation. Either saying that best is not defined. Okay, because best district in below the track class. Okay, so what we have to do, we have to move this scored above. Okay, So what we can do? We will write their declaration. So this is the declaration, okay? And here we can ride the definition. So now we will not get compilation. It'd Okay, So Okay, so let's copy this court only. Okay, so Now let us call this function test from the mean. Okay, so test. Now let's in the file. Okay, so 10 20 again. 10. 20. So the 1st 1 is due to buy sprint function. The 2nd 1 is due to the global function, which is the friend off the class. Okay. Okay. So one thing to note here is this test and this print function. They are not the part off class, okay? They're not the part off a class. So? So these two functions are not depart after class. So if I declare another function, if I defined another functioning headlights of wide display and inside the display function , so can I write. See out this Ed Wicks. Can I write this? So is this line correct? Obviously, this is correct. So what is the meaning off this? This will contain the address of the current object so I can access the private property inside the class. So this is correct. This implicitly means see out. Eto x c out X. Okay. Seduce implicitly. Missed this only. Okay, so what is the point? I want to make here is friend function? Do not have access to this pointer. Okay, so I am writing some points here. Okay, so first of all friend function do not have access to this point. Why? Because friend function are not the part of the class. Okay, friend function are not the part of the class, so they do not have access to this pointer. Okay? Now, the second point is, we can put the friend function under any excess modifier. Okay? So we can put these friend functions under any excess. Mortified? There will be no change. Okay, No effect. So the point is the excess mortifying Do not work for friend function. Okay, so I'm writing here. Excess modify It does north book for friend function by because the access modified defined the accessibility of the members of the class and friend functions are not depart of the class since friend function, not the part of the class that excess modifier cannot be used for friend function. So what I want Oh say here is so here The friend functions are in that the public we can move it to protect it. And we can also move it to private. Okay, there will be no changes. Okay, now what? I want is so we have a bus class inside the bus class. Let's say we have many functions. So Brende one function similarly, we have burned to function. Brent three functions brand four function and so on. Okay, so inside the bus class, suppose we have many functions. Okay? And all these functions want to excess the secrets off class. Okay. All these functions wants to access the private in the protected properties off the track class. So there are two ways to do this. So the first rays, what we will do, we will make all these functions as friend function off their true class. Okay, so this is the first week the second day. The shortcut is what we will do. We will make the bus class as a friend off a class. Okay. We will make bus class. Who really clear bus class as a friend off a class. So the same Texas. Very simple. Okay, so let's commend these trains. So what I want to do, I want to make I want to make I want to declare I want to declare bus as a friend off class . So this in Texas. Very simple friend. The us, but OK, so what will happen with the help of this lane? So with the help of this line, But I want to say here is now the class bus is a friend off track. Plus Okay, so all the functions, although all the member function of the bus class can exist all the properties off the truck class. Okay. Every member function of the bus class is now a friend of the truck class. Okay, so these type of class is this type of classes are called friend classes. OK, so this type of classes are called friend classes, so we know what our friend glasses. Okay. Now the fourth point is the friendship is when we so we have one of your friendship. So what is the meaning off when their friendship? So what is the meaning of a new friendship? So the ice truck has declared, but as his friend so best can access all the properties off the track class. OK, But the vice ever said is not true. OK, but can access all the properties of ultra class because Struck has declared but as its friend. But the vice a versa is not true. truck cannot access the private and the predicted properties off the bus class. Okay, because bus has not declared truck as his friend now. Okay, The car's bus has not declared truck as his friend yet. Okay, So the friendship is when their friendship. Okay, so when we're friendship and we know what is a friend? Class excess modified overlord work for friend classes and Fran classes do not have access to this pointer. Okay, friend, functions do not have access to this point there. Okay, So I hope everything is cleared. Thank you.