1
00:00:00,430 --> 00:00:01,690
Hello, my name is Typhoon.

2
00:00:01,690 --> 00:00:07,920
And in this lecture of our oxide course, we will learn about the another necessary requirement of ADT

3
00:00:07,960 --> 00:00:08,380
here.

4
00:00:08,380 --> 00:00:10,030
So let's get started.

5
00:00:22,260 --> 00:00:30,900
Another requirement of ADT is that it has to be able to control all copy operations to avoid dynamic

6
00:00:30,900 --> 00:00:34,350
memory aliasing problems caused by a shallow copy.

7
00:00:34,350 --> 00:00:38,490
So some members of the copy may reference the same objects as the original.

8
00:00:38,490 --> 00:00:43,590
So for this purpose we can use the assignment operator overloading as the sample.

9
00:00:43,590 --> 00:00:48,150
We will refactor the dog class so it now has the copy assignment.

10
00:00:48,150 --> 00:00:48,510
Operator.

11
00:00:48,510 --> 00:00:54,690
So the code here we will write now is inside the dog class.

12
00:00:54,690 --> 00:00:58,230
We have the public, the constructor here.

13
00:00:59,120 --> 00:01:03,680
As you can see here, and we are class dog animal.

14
00:01:03,680 --> 00:01:08,720
So we will forward the forward forward to the constructor arguments.

15
00:01:08,720 --> 00:01:13,250
And now we're going to create some, uh, assignment operator overloading.

16
00:01:13,250 --> 00:01:17,900
So void operator, void operator here.

17
00:01:17,900 --> 00:01:23,630
And we will make the const dog here and dog.

18
00:01:25,200 --> 00:01:27,240
So under here.

19
00:01:29,240 --> 00:01:32,570
And my name equals the dot.

20
00:01:33,170 --> 00:01:33,950
My name.

21
00:01:35,210 --> 00:01:38,090
So we have the string name.

22
00:01:39,090 --> 00:01:41,520
Is a private member of animal.

23
00:01:41,730 --> 00:01:49,740
So now we will change this my name to protected instead of private.

24
00:01:51,250 --> 00:01:52,620
Take that here.

25
00:01:53,280 --> 00:01:57,600
So as you can see here, error is gone without turning it to public.

26
00:01:59,250 --> 00:02:01,620
Here we write the.

27
00:02:03,710 --> 00:02:04,630
Copy assignment.

28
00:02:04,640 --> 00:02:07,730
Uh, the forward copy assignment operator Overloading here.

29
00:02:07,730 --> 00:02:10,820
This is just a copy assignment overloading.

30
00:02:10,820 --> 00:02:14,690
And now we will implement the interface.

31
00:02:15,650 --> 00:02:18,050
As you can see, the interface is implemented here.

32
00:02:18,380 --> 00:02:22,130
Now let's actually run with the here.

33
00:02:22,130 --> 00:02:24,170
So now we will use a dog.

34
00:02:24,170 --> 00:02:25,970
Dog here, dog.

35
00:02:26,150 --> 00:02:29,990
This is our is going to be here terrier.

36
00:02:31,870 --> 00:02:36,220
And after that see out dog dot get name.

37
00:02:37,390 --> 00:02:39,640
That terrier is barking.

38
00:02:40,300 --> 00:02:42,280
Is barking.

39
00:02:47,630 --> 00:02:53,090
So and see out dog that make sound.

40
00:02:53,780 --> 00:02:54,890
And line.

41
00:02:55,070 --> 00:02:56,090
And line.

42
00:02:56,810 --> 00:02:59,780
So here is going to be the the.

43
00:03:01,200 --> 00:03:03,720
Terrier is barking.

44
00:03:03,720 --> 00:03:07,110
And after that it's going to be woof, woof here.

45
00:03:07,380 --> 00:03:09,540
And after that, we will also create a dog, too.

46
00:03:09,570 --> 00:03:10,080
Here.

47
00:03:10,500 --> 00:03:11,270
Dog.

48
00:03:11,280 --> 00:03:12,210
Dog two.

49
00:03:12,210 --> 00:03:14,730
And here we're going to use the dog here.

50
00:03:15,060 --> 00:03:18,960
As you can see here, this is we are going to take this dog and put it here.

51
00:03:19,320 --> 00:03:21,120
You will see why here.

52
00:03:21,240 --> 00:03:26,310
See out dog two dot get name.

53
00:03:26,640 --> 00:03:28,320
And this is going to be it's.

54
00:03:29,860 --> 00:03:32,800
Is marking is barking here.

55
00:03:34,340 --> 00:03:43,160
And after that see out.to dot make sound and in line.

56
00:03:43,940 --> 00:03:49,220
So we have added the copy assignment operator, which is overloading the doc class.

57
00:03:49,220 --> 00:03:55,490
However, since we try to access the my name variable in the base class from the drive class, we need

58
00:03:55,490 --> 00:03:58,520
to make the my name protected here.

59
00:03:58,520 --> 00:04:02,780
So if we make this private, we will access this outside the class here.

60
00:04:02,780 --> 00:04:06,280
And as you can see here, we need to make it private but not public here.

61
00:04:06,290 --> 00:04:10,190
But not protected, but not public here protected.

62
00:04:10,910 --> 00:04:17,840
So in the main method, when we copy the dog to dog to oops, actually.

63
00:04:17,840 --> 00:04:18,000
Yeah.

64
00:04:18,440 --> 00:04:22,190
The dog to dog to here.

65
00:04:24,510 --> 00:04:24,930
Yeah.

66
00:04:24,930 --> 00:04:32,820
So when we copy the dog to dog two, we can ensure that this is not a shallow copy.

67
00:04:33,390 --> 00:04:35,010
Let's run our program again.

68
00:04:35,040 --> 00:04:35,450
Oops.

69
00:04:35,460 --> 00:04:36,900
Here with this.

70
00:04:37,620 --> 00:04:40,890
And as you can see here, we got the same result.

71
00:04:40,890 --> 00:04:41,100
It's.

72
00:04:41,100 --> 00:04:42,120
Except it's actually.

73
00:04:42,120 --> 00:04:42,480
Yeah.

74
00:04:43,620 --> 00:04:48,280
And as you can see here, this is not a shallow copy.

75
00:04:48,300 --> 00:04:50,190
So in next lecture, I'm waiting you.
