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 ritual functions.
So virtual functions are those functions that are present in the base class and they're overwritten
in the derived classes.
Okay.
In this will do I want to discuss about pure virtual functions.
Okay I want to discuss about pure virtual functions.
So what are two or which functions.
So beyond what dual functions are virtual functions but they do not have definitions.
Okay so the functions that do not have a definition are called Pure virtual function.
So what is the syntax for creating a function.
Well tool so we will write the key word virtual and let's say we are talking about the print function
of difficult class.
So by writing the keyword by adding the keyword virtual this print function is now of virtual function.
Okay.
Now this is a normal virtual function.
I want to create a pure virtual function.
So the syntax for creating a pure virtual function is first of all we will write the keyword virtual
then let's say I'm converting this function into pure which will function.
So virtual white print and beyond what your function means they do not have definition.
So it will not have definition.
So this is the syntax for creating a pure virtual function okay.
It will not have definition.
Now the scene seeing good.
Okay now let's.
I'm coming despite so I want to create I want to convert this function and to pure virtual function.
So we have to remove the definition I am removing the definition and then we do not have a definition.
Okay.
So this is pure virtual function no
okay.
So this is the syntax for creating a pillar which will function simply no definition at all.
Okay.
Now we will see in some time why we need to build a virtual function.
What is the use case of build virtual function.
But before we all virtual function let us talk about abstract classes okay.
What types of classes and why do we need them.
So let us first try to understand what that abstract classes okay.
So if a class contain a pure virtual function then that class is an abstract class.
Okay.
So if a class contains a pure virtual function then that class will become abstract class.
So here we call is an abstract class because it is containing a pool which will function.
Okay simple.
Now what is the meaning of abstract.
So abstract means incomplete.
Okay so this class is an incomplete class.
Why is incomplete because it is having a function it contains a function that doesn't have definition.
Okay.
Now what is the purpose of abstract classes.
So if a class is an abstract class then if you will try to create the object of the abstract class then
you will get an error.
Okay.
So basically we cannot create object of abstract classes.
Okay since we call is an abstract class.
So if we will try to create the object of difficult class you will get an error.
Okay.
So if you will write we call v you will get an error and that it will be that we call class is an abstract
class so you cannot create the object of the F classes.
Okay.
Now let's see called
so let us come into everything
okay.
So we have only we call we.
Okay now let us try to run this file so the output will be that we could class.
We will get an error and that will be.
So let's see that it so that it is because class is an abstract class and we cannot create the object
of the abstract classes.
Okay.
Simple enough.
Now there is one more thing that will happen since so this is we cut glass and we have a glass cut which
in height from the we clicked glass we could Glass has now become an abstract glass because it contains
a pure virtual function.
Okay.
No glass.
God has two options glass God has two options.
First option is that it will implement all the pure white gel function of the wickedness so implement
all the pure virtual functions of difficult glass all pure virtual functions of because less.
Okay now the second way the second option is it will not implement all pure white will function.
So what will happen this glass car will become abstract glass.
It will also become abstract glass okay.
So Glass car has two options.
First first option is implement all the power watch and function of the vehicle glass.
Then in that case the glass car will become a normal glass and then we can create the object of the
car glass.
The second option is if it will not implement all the pillar which will function if it will not give
the definition of purely virtual function.
Then in that case it will become an abstract class.
Okay.
And we will not be able to create the object of the car class.
Okay so in this case we can see here brain function is a pure virtual function and the class card is
giving the definition of B all right dual function all the poor which is function of the vehicle class.
So in this case this is a normal class.
This is right.
But if you will remove the print it will remove the implementation of the print function.
Then the car C will throw this added value because it dies also become an abstract class incomplete
class.
Why it has become an abstract class because if will see the structure of the car.
Class you can see very carefully that this is class got since this class got inherits from the vehicle
class and we could class has a function has an incomplete function so the class card also has this incomplete
function.
Okay.
This class card also has this incomplete function.
The class is an abstract class also so we cannot create the object of the car class.
Okay.
Now let's see in code so.
Okay so let's remove the definition
since.
Okay so first we have definition since we have a definition we can create the object of the car class.
Okay so if we will write Ghazi then this is right.
Okay so our goal will be working.
So what code is working.
Okay.
Now if I will remove this print function.
So this car class has also become and have class and this time it will run this file.
We will get an added.
Okay so we are getting an edit and let's see that it so the class card is an abstract class.
Okay.
So now we have understood what our what dual functions and what that abstract classes.
Okay so one more thing.
What are beautiful classes.
Okay so there is something called pure abstract classes so we know where that abstract class there is
something called pure abstract classes what are pure abstract classes.
So since the vehicle we call is a beautiful class because it has only one function and that function
is a pure function pure ritual function.
Okay so pure abstract class means if an abstract class has all the functions as below what you'll function
so all functions will be pure virtual then that class will be pure after class.
Okay.
So this vehicle.
Okay so we have this we could class this vehicle.
Class can have many functions.
Okay let's say brain function and let's say getters and setters okay.
So this brain function is a virtual build virtual function.
Okay.
So this this is a pure virtual function.
Various trendsetter they have definitions so they are not pure virtual function.
So in that case this class is only abstract class.
We'll call this class only abstract class via abstract because it is containing a pure virtual function.
But if the getters and setters they are also pure virtual okay.
If I really make if I will remove the definition of Gordon setter I make them zero then this wicked
class is containing all the functions as pure virtual functions.
Then this abstract class will recall less during class.
Okay so perfect class means all the function of the class will be pure virtual.
Okay simple enough.
Now we have understood the meaning of abstract classes and the pure virtual function.
Now let's see the use case.
Let's discuss about the use case.
So in the last video we discussed we took an example of an employee an organization which want to give
salary to the people and thus any form level were different.
So they were for employees H.R. manager engineer and others.
Okay.
And what we did was we created an employee at a so this was off tape.
Employee start this was of type employee style so the first index zero was pointing towards an object
of H.R. plus then manager and then ingenious and others.
Okay.
And then we related over this area and then we did then inside the loop we did something like this.
E to calculate salary function.
OK we are calling the calculate salary function but with the help of e we can only access we can only
access the properties of the Employee class that is the base class.
We can only access the properties of the Employee class only the base class.
So that's why we have to create a calculate salary function inside the Employee class and that function
was virtually okay.
Why.
Well just because we have to decided the right time that which function to be called.
Okay.
So everything was working fine.
Okay.
So we cleared it.
Because we're still functioning inside the Employee class and that function was well still function.
Okay.
So everything was fine but I want to what I want to say here is now this calculate salary function should
be a pure virtual function not only what it should be pure virtual okay why pure virtual because I cannot
decide what will be the salary inside the Employee class how can I give the definition of conclude salary
function.
Okay I cannot give the definition of calculate salary function.
Okay so since I cannot give the definition what I will do I will make this function as pure virtual
function.
Okay.
Since this function has become the pure virtual function we cannot create our object of type employee.
Okay we can create we what we have to do we have to create a new class if we want to add another member.
Okay let's say any other member new stuff or something.
Okay so this is the use case of pure virtual function.
There is one modulus case for example if we want to force a child class to implement the function.
Okay so what do you want to do.
I have a child class and I want their child class.
I have a child class and I want that 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 base class I will make this function as pure what will function.
Okay so that the child the class will be enforced to implement their definition of disputed virtual
function otherwise the child's class will become the abstract class okay.
So you can take one more example of how the pure module function can be used for example I have an animal
class inside the animal.
We have like Tiger cow hooves.
Exactly.
So this animal class has a function.
Let's say you'd function.
Okay.
And the Tiger go and hose.
Okay.
They will have the.
You'd function.
So what we can do we can make this you'd function as pure virtual.
Okay because it cannot give their definition of you'd function inside the animal class.
So we will make this eat function as pure module function in this way the tiger class it will have it
on its function it will give the definition of its own function call will give the definition of its
own function and the horse will give the definition of its own function.
Okay so this is the use case of build which will function.
Okay so I hope everything is clear.
No thank you.