Hello, my name is Stephan.
And in this lecture of our course, we will continue our project on ADTs.
So let's get started.
So we will add a virtual method named Makesound.
And the virtual method is a method that has no implementation yet and only has the definition.
Also known as the interface.
So the derived class has to add the implementation to the virtual method using the override keyword.
So or else the compiler will complain about it.
So after we have a new animal class, we will make a class named dog that derives from the animal class.
So here we will add the animal here.
So after that we will.
As you can see, we have.
This animal.
And we have the constructor get give name and get name so we don't actually need the give name here
since we are giving name using the constructor here, but we can also use that in case if in if we need
it.
But we don't need it for now.
And after that we will create a new class class here, dog.
And this is we're going to make it the public class.
Public, actually.
Yes, we will make it a public class so the class dog will implement the public animal.
Public animal.
And after that we will write our class.
So in this case, we're going to use the public keyword and we will forward the constructor arguments.
So the dog here, we're going to use the string name and here we're going to use the.
Animal name.
Animal and name.
We will forward this the string name to our animal name here.
So animal name and here.
After that, we will also need to implement the interface.
So here we're going to make the string here, make sound, make sound and we will it.
And the sound is going to be, of course, the woof, woof.
Like this is what the dog sound like when they are woof, woof here.
So here we will use a return.
Woof, woof.
Wolf, here.
And as you can see, we got an error here.
So a virtual member can be marked override here.
So now.
No problem here.
Obviously.
And this is because the string makes sound.
All right, Here, we'll have to return Wufoo and make it like that.
And here.
Class dog public here.
And this is going to return the woof woof here.
Now we will write it like that.
We're going to create a new class named Doc here.
Doc is going to be let's name our doc is the.
Here.
Hound here.
And see out.
Dot get name.
Get name is gonna be is barking.
So.
And after that.
See out, See out.
Dog not make sound.
Of course.
It's the Maxent.
We'll return the woof woof here.
So make sound is going to be, uh, the Our hound is barking and woof, woof.
Here.
We have a problem here.
We have string name and animal we passed here.
Which is gonna to overeat.
And here we will add the virtual interface in our.
As you can see, we have an error here and we will add the virtual interface to our animal class.
So now after the animal constructor here, we will add the virtual virtual string.
So we, we can also use the integer because but we will get an error because this returns string here.
So we need to use the virtual type here.
The string and the string is going to be makesound.
So the interface has the implemented in derived class here.
So zero for example.
And here.
We have.
So actually now we can also run our application now and see.
As you can see, Hound is barking.
Woof, woof here.
So now we have two classes, the animal class here, actually.
Let's see here we have the animal class as the base class, and we have the dog class as a derived class.
So as shown here, the dog class has to implement the make sound method.
And it has been defined as a virtual method here in the animal class.
So if we delete this.
And as you can see, we got an error here.
We can create the haunt here.
So.
And the instance of the dog class can also invoke the getName method, even though it's not implemented
inside the dog class, since derived class derives all the class behavior to itself.
So if you run this code again, we will see this output here.
So let's actually compile and run inside here.
CLS or plus plus Main.cpp output dog dot x and dog dot x here.
And as you can see here, hound is barking.
Woof, woof.
Here.
Uh, that's our.
And again, we can say that the dog ADT has two functions and they are the these are the two functions.
They are getName and make sound functions.
But as you can see, we have no getName functions inside the animal class and the.
Another necessary comment will be discussed in next lecture about ADT.
So I'm waiting you in next lecture.