So now I want to create a temporary variable, or temporary object, using the num variable. All right. So, and we have to create this temporary object because this is what we have to return. Then right away, I'm going to go ahead and say the number becomes what the number used to be, modulus 12 plus 1. Or I could have used two lines of code, no problem. I'm going to go ahead and just use one line of code here.
And then I return that temporary variable. So by returning that temporary variable, it's going to have the old number. However, anytime you use this object again, it's going to be using the new one. So you can see the ++ on the left hand side does not create an additional object. You see that?
The ++ on the right hand side creates an additional object, so we have the old state of that object that we can return. So that's why the pre-incrementor is faster than the post-incrementor. And if speed is of concern, if you're in a really limited memory location, then you want to use the pre-incrementor with everything.
All right. So now that's my ++ operator. And now we want to do it with the -- minus operator. So with this right here, we're going to go ahead and say this is going to be our -- month. And this is going to be pre-decrement-- decrement just means decreased by 1-- operator. And then we're going to say the month object is what's going to get returned. And we're overloading the -- operator. So curly brace, Enter key.
And then we're going to say, if the number is less than or equal to 1, then the number becomes 12. Let's see, how should we do this? How about if we simply say, -- num, like that. So I'm going to decrease by 1. And then I want to say, if the number is less than 1, then we're going to set the number to 12, because the 0 needs to be 12. OK?
And then we're going to return dereference this pointer. So we need to return back an object, OK, so we're going to dereference this object. So I'm going to subtract by 1. And if we go 0, it becomes 0, then we're going to set it to 12. So that should work really well.
All right. So now let's do the other one. And then we're going to say this is going to our month, --, and this is called a post-decrement operator. And again, the only difference-- operator-- is by putting the word int inside of the parentheses. So that tells C++ that we're doing this one, right here. And we have to have the old state. So I'm going to create an object with the old state.
And then I'm going to say minus minus num. And then I'm going to say, if num is less than 1, that means a negative, then num needs to be set to 12. All right? And then I'm going to return the old state. So I'm going to return 10. This is the old state. However the object has now been changed. So when I use it again, it's going to have the new value. And that looks good.
All right, let's see what's next. Also overload the output stream and input stream operators, so that the output stream operator displays month name, and the input stream operator allows the user to input a month number. So we can do that. So when you're overloading the input and output operators, you want to-- the input stream operators and the output stream operators-- you want to do it outside of the class.
So you would normally do it in your implementation file. And since this all needs to be one single file, I'm going to do it below the class, down here. But keep in mind, if this was production, I would actually be doing a header file, I would do an implementation file. All right? So we need to return back the output stream address, like that. So I'm going to return back the output stream address. And then I'm going to overload the output stream operator.
And to overload the output stream operator, again, Google. No problem at all. Just Google it. We find out, we find out the syntax, and then we implement it. So I'm going to say output stream, and I'm going to get the address of the output stream. And then I'm going to put in the word const to make sure that this input object does not change, even accidentally. OK.
And the object needs to be a month object. And I'm going to get the address of the month object that is being given to me. All right? Curly brace, Enter key. Then what I'm going to do is I'm going to append to that output stream, I'm going to append the current month that I was given, and I'm going to use the getname method, like that. Then I'm going to return the output stream, like that.
So address of month, getname, [INAUDIBLE]. The object has type qualifiers that are not compatible with month, getname. Constant month, and-- All right. Let me check and see if I brought in the string. I brought in the string. arrow, arrow, output string, constant months.
The object has type qualifiers that are not compatible with member function, getname. So I'm going to go look at my getname, and object type is const, month. And then let's go look at that getname. Getname, if the number is less than that, we're going to return the string. Otherwise we're going to return a month name.
Let's see if pulling off the const is going to fix it. It's not liking the const there, so I'm going to go ahead and pull that off. And this is going to give the address of the month name. Month, getname. We send that to our output stream, which is here. And then we return the output stream. All right. That looks OK. All right.
Let's keep going. All right. Now we also want to do the input stream. So I need to return back the address. So you can see that I'm taking the output stream, I'm sending more stuff to it, and then I'm going to send back the address of that output stream so that the cout statement can continue adding and appending more stuff to that output stream. All right? So I'm basically just adding a little bit here. So I pull it in, I had a little bit based on the month that I've received, and then I return it back so the cout can keep on going.
[End of Audio]