WEBVTT

00:00.430 --> 00:01.690
Hello, my name is Typhoon.

00:01.690 --> 00:07.920
And in this lecture of our oxide course, we will learn about the another necessary requirement of ADT

00:07.960 --> 00:08.380
here.

00:08.380 --> 00:10.030
So let's get started.

00:22.260 --> 00:30.900
Another requirement of ADT is that it has to be able to control all copy operations to avoid dynamic

00:30.900 --> 00:34.350
memory aliasing problems caused by a shallow copy.

00:34.350 --> 00:38.490
So some members of the copy may reference the same objects as the original.

00:38.490 --> 00:43.590
So for this purpose we can use the assignment operator overloading as the sample.

00:43.590 --> 00:48.150
We will refactor the dog class so it now has the copy assignment.

00:48.150 --> 00:48.510
Operator.

00:48.510 --> 00:54.690
So the code here we will write now is inside the dog class.

00:54.690 --> 00:58.230
We have the public, the constructor here.

00:59.120 --> 01:03.680
As you can see here, and we are class dog animal.

01:03.680 --> 01:08.720
So we will forward the forward forward to the constructor arguments.

01:08.720 --> 01:13.250
And now we're going to create some, uh, assignment operator overloading.

01:13.250 --> 01:17.900
So void operator, void operator here.

01:17.900 --> 01:23.630
And we will make the const dog here and dog.

01:25.200 --> 01:27.240
So under here.

01:29.240 --> 01:32.570
And my name equals the dot.

01:33.170 --> 01:33.950
My name.

01:35.210 --> 01:38.090
So we have the string name.

01:39.090 --> 01:41.520
Is a private member of animal.

01:41.730 --> 01:49.740
So now we will change this my name to protected instead of private.

01:51.250 --> 01:52.620
Take that here.

01:53.280 --> 01:57.600
So as you can see here, error is gone without turning it to public.

01:59.250 --> 02:01.620
Here we write the.

02:03.710 --> 02:04.630
Copy assignment.

02:04.640 --> 02:07.730
Uh, the forward copy assignment operator Overloading here.

02:07.730 --> 02:10.820
This is just a copy assignment overloading.

02:10.820 --> 02:14.690
And now we will implement the interface.

02:15.650 --> 02:18.050
As you can see, the interface is implemented here.

02:18.380 --> 02:22.130
Now let's actually run with the here.

02:22.130 --> 02:24.170
So now we will use a dog.

02:24.170 --> 02:25.970
Dog here, dog.

02:26.150 --> 02:29.990
This is our is going to be here terrier.

02:31.870 --> 02:36.220
And after that see out dog dot get name.

02:37.390 --> 02:39.640
That terrier is barking.

02:40.300 --> 02:42.280
Is barking.

02:47.630 --> 02:53.090
So and see out dog that make sound.

02:53.780 --> 02:54.890
And line.

02:55.070 --> 02:56.090
And line.

02:56.810 --> 02:59.780
So here is going to be the the.

03:01.200 --> 03:03.720
Terrier is barking.

03:03.720 --> 03:07.110
And after that it's going to be woof, woof here.

03:07.380 --> 03:09.540
And after that, we will also create a dog, too.

03:09.570 --> 03:10.080
Here.

03:10.500 --> 03:11.270
Dog.

03:11.280 --> 03:12.210
Dog two.

03:12.210 --> 03:14.730
And here we're going to use the dog here.

03:15.060 --> 03:18.960
As you can see here, this is we are going to take this dog and put it here.

03:19.320 --> 03:21.120
You will see why here.

03:21.240 --> 03:26.310
See out dog two dot get name.

03:26.640 --> 03:28.320
And this is going to be it's.

03:29.860 --> 03:32.800
Is marking is barking here.

03:34.340 --> 03:43.160
And after that see out.to dot make sound and in line.

03:43.940 --> 03:49.220
So we have added the copy assignment operator, which is overloading the doc class.

03:49.220 --> 03:55.490
However, since we try to access the my name variable in the base class from the drive class, we need

03:55.490 --> 03:58.520
to make the my name protected here.

03:58.520 --> 04:02.780
So if we make this private, we will access this outside the class here.

04:02.780 --> 04:06.280
And as you can see here, we need to make it private but not public here.

04:06.290 --> 04:10.190
But not protected, but not public here protected.

04:10.910 --> 04:17.840
So in the main method, when we copy the dog to dog to oops, actually.

04:17.840 --> 04:18.000
Yeah.

04:18.440 --> 04:22.190
The dog to dog to here.

04:24.510 --> 04:24.930
Yeah.

04:24.930 --> 04:32.820
So when we copy the dog to dog two, we can ensure that this is not a shallow copy.

04:33.390 --> 04:35.010
Let's run our program again.

04:35.040 --> 04:35.450
Oops.

04:35.460 --> 04:36.900
Here with this.

04:37.620 --> 04:40.890
And as you can see here, we got the same result.

04:40.890 --> 04:41.100
It's.

04:41.100 --> 04:42.120
Except it's actually.

04:42.120 --> 04:42.480
Yeah.

04:43.620 --> 04:48.280
And as you can see here, this is not a shallow copy.

04:48.300 --> 04:50.190
So in next lecture, I'm waiting you.
