WEBVTT

00:00.410 --> 00:01.700
Hello, my name is Stephan.

00:01.700 --> 00:05.940
And in this lecture of our course, we will continue our project on ADTs.

00:05.960 --> 00:07.340
So let's get started.

00:19.240 --> 00:23.440
So we will add a virtual method named Makesound.

00:23.440 --> 00:30.970
And the virtual method is a method that has no implementation yet and only has the definition.

00:31.000 --> 00:32.290
Also known as the interface.

00:32.290 --> 00:39.640
So the derived class has to add the implementation to the virtual method using the override keyword.

00:39.640 --> 00:42.760
So or else the compiler will complain about it.

00:42.760 --> 00:50.260
So after we have a new animal class, we will make a class named dog that derives from the animal class.

00:50.470 --> 00:57.010
So here we will add the animal here.

00:57.310 --> 00:59.200
So after that we will.

00:59.200 --> 01:00.250
As you can see, we have.

01:01.270 --> 01:02.230
This animal.

01:04.120 --> 01:10.420
And we have the constructor get give name and get name so we don't actually need the give name here

01:10.420 --> 01:17.500
since we are giving name using the constructor here, but we can also use that in case if in if we need

01:17.500 --> 01:17.620
it.

01:17.620 --> 01:19.390
But we don't need it for now.

01:20.230 --> 01:26.070
And after that we will create a new class class here, dog.

01:26.080 --> 01:29.470
And this is we're going to make it the public class.

01:33.140 --> 01:36.320
Public, actually.

01:37.140 --> 01:44.370
Yes, we will make it a public class so the class dog will implement the public animal.

01:44.670 --> 01:46.620
Public animal.

01:47.360 --> 01:52.130
And after that we will write our class.

01:52.160 --> 01:58.430
So in this case, we're going to use the public keyword and we will forward the constructor arguments.

01:58.430 --> 02:06.440
So the dog here, we're going to use the string name and here we're going to use the.

02:07.460 --> 02:08.420
Animal name.

02:08.930 --> 02:10.040
Animal and name.

02:10.040 --> 02:17.330
We will forward this the string name to our animal name here.

02:17.330 --> 02:21.170
So animal name and here.

02:22.950 --> 02:27.150
After that, we will also need to implement the interface.

02:27.150 --> 02:35.310
So here we're going to make the string here, make sound, make sound and we will it.

02:36.370 --> 02:39.410
And the sound is going to be, of course, the woof, woof.

02:39.460 --> 02:44.620
Like this is what the dog sound like when they are woof, woof here.

02:45.230 --> 02:49.010
So here we will use a return.

02:49.220 --> 02:50.270
Woof, woof.

02:52.380 --> 02:53.160
Wolf, here.

02:53.790 --> 02:56.130
And as you can see, we got an error here.

02:56.280 --> 03:01.230
So a virtual member can be marked override here.

03:01.620 --> 03:03.060
So now.

03:04.820 --> 03:05.800
No problem here.

03:06.610 --> 03:07.180
Obviously.

03:08.960 --> 03:12.110
And this is because the string makes sound.

03:12.150 --> 03:15.980
All right, Here, we'll have to return Wufoo and make it like that.

03:16.550 --> 03:17.780
And here.

03:23.570 --> 03:26.480
Class dog public here.

03:26.480 --> 03:29.240
And this is going to return the woof woof here.

03:30.620 --> 03:32.480
Now we will write it like that.

03:33.170 --> 03:35.810
We're going to create a new class named Doc here.

03:36.140 --> 03:41.480
Doc is going to be let's name our doc is the.

03:42.400 --> 03:42.910
Here.

03:43.930 --> 03:45.160
Hound here.

03:46.950 --> 03:49.350
And see out.

03:51.010 --> 03:52.660
Dot get name.

03:53.940 --> 03:58.860
Get name is gonna be is barking.

03:59.880 --> 04:00.900
So.

04:00.900 --> 04:01.740
And after that.

04:01.740 --> 04:04.890
See out, See out.

04:08.580 --> 04:10.890
Dog not make sound.

04:11.850 --> 04:12.240
Of course.

04:12.240 --> 04:13.710
It's the Maxent.

04:13.740 --> 04:16.560
We'll return the woof woof here.

04:16.710 --> 04:24.150
So make sound is going to be, uh, the Our hound is barking and woof, woof.

04:24.180 --> 04:24.630
Here.

04:27.540 --> 04:29.280
We have a problem here.

04:31.250 --> 04:35.560
We have string name and animal we passed here.

04:36.550 --> 04:38.260
Which is gonna to overeat.

04:43.210 --> 04:48.910
And here we will add the virtual interface in our.

04:48.910 --> 04:54.920
As you can see, we have an error here and we will add the virtual interface to our animal class.

04:54.940 --> 05:01.290
So now after the animal constructor here, we will add the virtual virtual string.

05:01.300 --> 05:07.390
So we, we can also use the integer because but we will get an error because this returns string here.

05:07.390 --> 05:10.810
So we need to use the virtual type here.

05:10.840 --> 05:16.540
The string and the string is going to be makesound.

05:17.630 --> 05:21.110
So the interface has the implemented in derived class here.

05:21.290 --> 05:24.560
So zero for example.

05:24.710 --> 05:26.810
And here.

05:28.010 --> 05:28.460
We have.

05:29.450 --> 05:34.680
So actually now we can also run our application now and see.

05:34.700 --> 05:36.890
As you can see, Hound is barking.

05:36.920 --> 05:38.030
Woof, woof here.

05:38.210 --> 05:42.640
So now we have two classes, the animal class here, actually.

05:42.650 --> 05:53.350
Let's see here we have the animal class as the base class, and we have the dog class as a derived class.

05:53.360 --> 06:00.770
So as shown here, the dog class has to implement the make sound method.

06:00.860 --> 06:07.940
And it has been defined as a virtual method here in the animal class.

06:07.940 --> 06:09.410
So if we delete this.

06:11.720 --> 06:13.970
And as you can see, we got an error here.

06:15.290 --> 06:16.820
We can create the haunt here.

06:18.170 --> 06:18.650
So.

06:22.440 --> 06:32.010
And the instance of the dog class can also invoke the getName method, even though it's not implemented

06:32.010 --> 06:40.020
inside the dog class, since derived class derives all the class behavior to itself.

06:40.380 --> 06:47.520
So if you run this code again, we will see this output here.

06:47.520 --> 06:50.020
So let's actually compile and run inside here.

06:51.540 --> 07:01.050
CLS or plus plus Main.cpp output dog dot x and dog dot x here.

07:01.050 --> 07:04.440
And as you can see here, hound is barking.

07:04.440 --> 07:05.190
Woof, woof.

07:05.190 --> 07:05.570
Here.

07:06.530 --> 07:08.000
Uh, that's our.

07:08.010 --> 07:15.660
And again, we can say that the dog ADT has two functions and they are the these are the two functions.

07:15.660 --> 07:18.990
They are getName and make sound functions.

07:18.990 --> 07:25.920
But as you can see, we have no getName functions inside the animal class and the.

07:27.120 --> 07:31.510
Another necessary comment will be discussed in next lecture about ADT.

07:31.580 --> 07:33.720
So I'm waiting you in next lecture.
