Hello everyone.
So in the last video we discussed overloading the incremental operator.
I hope that is clear in this video.
We will try to overload a few more operators.
Okay so let's start with the plus plus operator.
So let's start with the post increment operator.
Okay.
So in this video we will try to overload post increment operator.
Okay.
So this is a unity operator.
Okay.
So how we will call friction f1 plus plus.
Okay.
Since this is a unity operator so F1 will go in this and there is no need to pass any argument.
Okay.
So first let us try to first let us revise the defense within the pre and post increment.
Okay.
So pre and post so there defenses see if I write and die is 5 and I bless plus and if I tried to print
the value off.
So this is P so plus plus I.
And if I tried to print the value of i.
So the output will be 6.
Okay.
And similarly if I had to post increment and if I tried to print the value of my then I said will be
six.
So here that there is no difference.
The difference would have come when we will assign the values.
Okay.
So the difference between post and increment will come when we will assign the values.
So let us assign the values.
So in the G.
This is less policy.
And now let's try to bend the value of i n g
similarly
I plus press and brand the value of i n g
so the value of i will be 6 and the value of G will also be 6.
In this case the value of i will be 6.
But the value of j will be five.
Okay.
So what happened is breeding commences first increment and then use.
Okay so that's why a six and 6.
Whereas post increment will say first assign first to use and then increment.
Okay.
So the defense will come when we will assign the values.
Okay.
Now how we will differentiate in diffraction plots.
Okay.
So what will happen infection plus how we will call the function so we will write something like
fiction if food is f 1 plus plus.
So let us assume the initial value of f1 is so numerator and denominator is that certain by two.
So this is initially F1 so posting I will say first assign and then increment.
So the value of a fourth will be same as the value of f1 so then n2.
So this will be our effort.
And for F1 which will happen we will do plus 1 and then we will call simplifying.
So it will become 6 by 1.
Okay.
So this will be the value of f1.
Okay so let us all load the function post increment.
Let us order.
Operator post increment.
Okay so what we will do we have to return a fraction and their function.
We have to return the all the value.
So this is the old value and this is the new value.
Okay.
So now let's see called
so it's time to overload post increment.
Okay so first of all work with the return type return type cannot be void because we have to return
type cannot be void because we can also assign values.
Okay so that's why than type cannot be void then they will be function only.
And then operator and then operator which we want to overload.
So it will not take any argument why because would say unity operator now see the name of the function
is exactly the same operator plus and operator plus.
So how do differentiate between the P and the post increment.
So what we will do we will write in budget here.
Okay.
So now this is post increment and that bonus pre increment.
Okay.
So you have to remember this that we have to pass in budget as argument.
Okay.
So what we have to do first of all we have to write down the friction and the friction with the all
the values.
Okay.
So friction with the all the values.
So friction if new it will contain the numerator and denominator.
And now what we have to do first first use and then increment.
Now we will increment.
So the numerator will become numerator plus denominator and the denominator will remain unchanged.
Then what we have to do we have to call simplify function so simplify so implicitly it will be called
on this side or simplify okay.
Now we have to return direction so that it can start.
Sorry we have to return the old friction and so f new.
Okay.
So what will happen.
So this is F1 numerator and denominator.
Value is tending to and suits at doses so hundred.
Okay so this will contain 700.
So I am creating a new fraction f new.
So we have a new friction no days down the runway.
That is true.
This is f new okay.
And let's say you said this is 800.
So numerator is numerator plus no matter.
So who is no better that this error numerator.
So 700 nobody knows.
So it will become 20 and this will remain as true then we are calling the simplified function.
So simplify we make it 6 by 1.
Okay.
And then we added dining f new.
So then we will return this one.
Okay so let's do one more thing.
Let us also simplify this friction so it will become 5 by 1.
Okay.
So let us call simplify function on f new
so f new not simplify
okay.
Now there does create a friction if three
so let's create a fraction F3 and we will use post incrementally we'll call post increment.
Okay so f one less plus and now we will print f linen F three so f t not print.
Okay so what should be our output.
Okay.
So since we are calling post incremental first F when will be assigned to F3.
So the value of F2 will be 5 by 1 because we are also calling simplify function and then f one will
be incremented.
So the value of f 1 will be 6 by 1.
So that would probably be 6 by 1 and 5 7.
Okay so let's see
so that would produce 6 by 1 in 5 by 1.
Okay.
So our code is working now let's see when.
If I had 8
and day is 5 and I bless bless and bless bliss.
And if I tried to pray in the valley of I.
So what do we are output.
So what I'm doing here is we are doing nesting nesting one post increment so it will throw us at it.
Okay.
So nesting is not defined for post increment.
Okay.
So nesting is not allowed for posting agreement.
So since nesting is not allowed.
So since nesting is not allowed for posting agreement.
So we will not do.
Okay so there is no need for us to do nesting.
Okay so if you will ring discord this will throw us at it.
Similarly our God will give us unexpected output.
Okay.
So very strange behavior will be observed okay.
So now let's stop let's stop posting agreement here.
Now let us try to overload one more operator which is called Blessed collaborator.
So now we will try to overload classical operator.
Okay.
So where this political operator.
So when I write in day 5 and geez let's say 3.
So if I do I plus equals G.
So this is basically the short form of writing I equals a plus G.
Okay so what will happen.
The value of AI is initially 5 and the value of G is initially 3.
So after this line it will become it.
Okay.
So add the two values and put that in there.
Then I okay.
So for political operator nesting is defined.
Okay so if I write I plus equal g and then if I do the nesting blessed with G so output will become.
So this will be done.
This will make the value of phys it and then we are doing plus it goes to you.
So this will become 11 and it will remain three.
Okay so the value of 5 will become eleven and the value of j will remain three.
Okay.
So this operator has nesting properties.
Okay so nesting is allowed.
So let's see.
Let's try to experiment first.
So what I'm doing in day is 5 and into juice 3 now I plus a equals G
similarly plus equals G.
Now if I tried to print the value of i in J
So that would probably be eleven and three guess it output is eleven and
so the output is eleven entry.
Okay.
So nesting is defined.
So that means we have to also uh keep this in mind divide overloading the operator.
Okay.
So how we will call our function
so we call something like this friction F1 plus it equals friction F2 since it is a binary operator.
So the F1 will go in this and F2 will be parsed as argument.
Okay so this simply means F1 is F1 plus F2.
Okay.
So we are adding two functions and put the desert inflection one.
Okay.
So if you see we have already done this function if you remember the add function.
So the function idea of ADD was something like this only okay.
So now let us see in code.
Okay.
So first of all what we the return type.
So the return type will be a fraction we are returning a fraction then since the nesting is allowed.
We will return biodefense.
Okay.
We have to return a fraction biodefense via biodefense because the nesting is allowed okay.
So let's see okay.
So let's see.
So first of all what do we the return types to return that will be a fraction.
Okay.
So why affliction.
Because we need to return affection.
It cannot be void and then operator keyword.
And the operative which we want to overload plus equal so it would but it will take it will take a fraction
as input and fiction if two now we know about gold standard offenses.
So we will pass constant traffic because you do not want to call copy constructor.
And also we want to avoid any legal changes.
Okay.
So the functionality will be same as add function.
So there is added function
okay.
So this is our idea function.
So we'll copy discord
okay.
So what we have to do here is we have to make the changes in F1 only.
Okay.
So oncoming discord and we do not need this code
okay.
Okay.
So once the numerator and denominator is updated we have to call the simplify function.
So after cutting the simplify function we also have to it done so right then stop this okay.
Now let's see
now let us first take two functions and see what will be our output.
So.
So let's say I have two factions F1 and F2.
So for F1 the values of the numerator and denominator is let's say 10 entry.
So this is fraction F1 and for fraction F2 let's say the values are 5 and 2.
So this is friction to address 800 and address 700.
Okay.
So when we add these to fiction what will be our output.
So our output will we assemble basics.
This is 20 plus 15 and this is tied to five by six.
So after calling the simplify function output will we try to five by six only.
Okay so this is our output.
Now how we will call this function we will call the function f plus equals F2.
Okay.
So F2 will remain unchanged.
So the value of have to will remain same as 5 by 2.
And F1 will become 25 by 6.
Okay.
So we are doing we are calculating that I'll see him and then we are updating the numerator and then
do a matter of this.
And this contains 700 basically F1.
Okay then we are calling this employ function and then we are returning F1.
Okay.
So let's see.
So how will you call the functions F1 plus equals F2.
So first of all let us change the values of a finite F2 as we have discussed.
So the value of f1 was 10 by three and the value of after was five by 2 5 and 2.
Okay so our output will be 35 by 6.
Now let us try to bring the value of f1 f2 so F1 nought point.
And similarly after that print.
So the value of two will remain unchanged and the value of f1 it will become five by six.
Okay
so the value of f1 became 25 by 6 and the value of employees 5 by two.
Okay.
So our code is working fine.
Okay.
So one more thing I hope you understand why we need to pass by reference written by reference.
Okay.
Y written by reference because if you will write if you will write like F1 plus equals F2
and then again plus equals F2 if you will do nesting.
So I feel lighter than biodefense than the output of this thing will be a system before a system or
temporary memory.
And this second plus equals two will work on that system memory.
Okay so that will be wrong.
Okay.
We do not want it to work on system copy.
So that's why we have to write down by reference.
Okay.
So if you want to condemn this file let us
okay.
So now that's in this file
so F2 remains unchanged and the value of f1 is 25 by three which I'm assuming is correct.
Okay.
So why we need to return biodefense.
So if you will not written by defence the output of this part it will be a system copy it will be a
system copy and this second plus equals two.
This will work on the system copy which we do not want.
Okay so that's why we have the written by reference.
Okay.
So I think we have all loaded almost all the imprint operators.
So if you have any doubt feel free to ask.
Okay.
Thank you.