Hello, my name is Typhoon.
And in this lecture of our oxide course, we will learn about the another necessary requirement of ADT
here.
So let's get started.
Another requirement of ADT is that it has to be able to control all copy operations to avoid dynamic
memory aliasing problems caused by a shallow copy.
So some members of the copy may reference the same objects as the original.
So for this purpose we can use the assignment operator overloading as the sample.
We will refactor the dog class so it now has the copy assignment.
Operator.
So the code here we will write now is inside the dog class.
We have the public, the constructor here.
As you can see here, and we are class dog animal.
So we will forward the forward forward to the constructor arguments.
And now we're going to create some, uh, assignment operator overloading.
So void operator, void operator here.
And we will make the const dog here and dog.
So under here.
And my name equals the dot.
My name.
So we have the string name.
Is a private member of animal.
So now we will change this my name to protected instead of private.
Take that here.
So as you can see here, error is gone without turning it to public.
Here we write the.
Copy assignment.
Uh, the forward copy assignment operator Overloading here.
This is just a copy assignment overloading.
And now we will implement the interface.
As you can see, the interface is implemented here.
Now let's actually run with the here.
So now we will use a dog.
Dog here, dog.
This is our is going to be here terrier.
And after that see out dog dot get name.
That terrier is barking.
Is barking.
So and see out dog that make sound.
And line.
So here is going to be the the.
Terrier is barking.
And after that it's going to be woof, woof here.
And after that, we will also create a dog, too.
Here.
Dog.
Dog two.
And here we're going to use the dog here.
As you can see here, this is we are going to take this dog and put it here.
You will see why here.
See out dog two dot get name.
And this is going to be it's.
Is marking is barking here.
And after that see out.to dot make sound and in line.
So we have added the copy assignment operator, which is overloading the doc class.
However, since we try to access the my name variable in the base class from the drive class, we need
to make the my name protected here.
So if we make this private, we will access this outside the class here.
And as you can see here, we need to make it private but not public here.
But not protected, but not public here protected.
So in the main method, when we copy the dog to dog to oops, actually.
Yeah.
The dog to dog to here.
Yeah.
So when we copy the dog to dog two, we can ensure that this is not a shallow copy.
Let's run our program again.
Oops.
Here with this.
And as you can see here, we got the same result.
It's.
Except it's actually.
Yeah.
And as you can see here, this is not a shallow copy.
So in next lecture, I'm waiting you.