Hello everyone.
In the last few videos we learned about constructor and this session we will try a few more interesting
examples
so this is our class student.
So the student class has one private property each and then we have our destructor our default constructor
and then we have to promote based constructor.
The first one takes a rule number as input and the second parameter is constructor take Agent.
Rule number as input.
And then we have a public field a public property rule number and then a public function display good
data function and stage function.
OK so now let us create some object
student S-1 now which constructed data you call it will required default constructor.
So constructor one called
so the default constructors construct seven then parameters constructor to which takes on the role number
is in Porter's constructor to.
And the constructor which takes a general number is constructor three.
Okay.
So in this case constructor one will be called
Student 2.
And let us give rule number as input.
Now which construct page will call it will call the constructor to
so constructor to called Story entry.
Now this time I will give a general number.
So 10 hundred no constructor table be called here
construct Petrie card
student for and as 3 as input.
STUDENT 3 As input now which constructively recoiled.
So copy construct level recall here
copy constructor call.
Now this copy constructors and world copy constructor.
Okay now what if I do still rent when it goes to rental now which constructively call ahead.
So no constructor will recall here but assign this to I'd already cleared in the memory.
So copy assignment operator will be called copy assignment operator.
Okay copy assignment operator called copy of a large recall here.
Why.
Because both S1 and S2 are already created the already existing memory.
Now let's take one more example.
Student s 5 equals S3.
Now which constructor will be called here.
Copy constructor
so copy constructor call here.
Now let's see
see what is the meaning of the slain we are creating a new object and then we are copying the values
of S3 into S5 so we can break this line into two lines.
First we are creating an object and then we are copying the value of student 3 OBJECTION TO STUDENT
5.
Okay so in this line default constructor will be called and add this line.
Copy assignment operator will be called okay.
Copy assignment operator will be called but if I see Add this line if I see this line then copy constructor
is being called.
Why.
Because what compiler ever do.
So these are two lines.
Okay so word compiler Lou would come by level Lou.
It will optimize it will convert these two lines into one single line compiler will optimize.
So optimize internally come by level interpreted compiler will interpret this line into one single line
which is student s 5 as 3 okay.
So compiler will interpret these two lines in this fashion so if you write student s faith equals S3
S3 this is same as to render S5 vector S3.
Okay so that's why copy constructor is called copy construct based.
Here.
Okay so this was the special case student that's equals S3.
This is a special case and you must remember it.
Okay so this time copy constructor will be called here and not copy assignment operator okay.
Thank you.