Hello, and welcome to the 51st sario in a c++ programming series, and in this part, we're going to be looking at this key word. The key word. This allows you to refer to an object to the object itself within itself, which allows you to use only its attributes and methods. Based on what I've just said, you might be thinking, What the hell, what the hell is something that we're gonna have to show you to actually truly illustrate what this keyword does. So let's go ahead and open up our project. And then we can just show you that this keyword in action.
And then you can feel the benefits of well, first of all, I want to create a simple class called vehicle. Do some public stuff and what we're going to do is a constructor. An overloaded constructor is going to take in speed into a And it's going to have local variable for in speed. And in the and now what we're going to do is implement this. So actually, before we implement it, we'll just create the object down here. So to create the object what we're going to do is vehicle called BMW.
Find the values 500 789 10 under STD C, in the video age, STD mine. So let's just implement the constructor so vehicle colon colon vehicle. And inside here It takes two parameters in speed and the age. We want to find these parameters respective the parameters respectively to its own local parameters. So we're going to do with speed equals Speed, at age. And now if we get that we get bills clearly.
But let's just open up the debug area we get a value of zero, imagine we've assigned speed to speed with the compiler on the node speed you're trying to assign to speed because it to illustrate what's happening if the cm, speed, CD and line was second, let's comment this out. And if we run this, we get a value of 500. Basically what it's doing is it's just assigning speed back to itself. So it's saying speed, which is when it gets passed in 500, just assigning speed back to itself. So nothing is actually affecting this arrow and the same with the age. But we use this key word We can access the classes that own properties and methods.
So if we do go to this, we do this. This is the way you do it, you do this dash greater than and then you access is variable. So if we do speed equals speed is basically save, assign the value of speed which is passed in to the class variable called speed. So if this we'll call it speed to, this will not work because it is saying there isn't a value or a variable called speed. That won't cause me to change it. And we can do the same for age as well.
And now we just see this out. We get a value of 789 for agent speed should be 500. So that's the sort of Sorry about that. That's the use of this keyword. That's it for this tutorial. If you have any questions, feel free to message us at support at sonar systems.
Kota UK, the email will be in the description. You can comment on this video or just directly message us via YouTube, or the recording for source code will also be in the description. The next part of this series we'll be looking at constant objects. If you have any questions I actually already said that and as usual, thanks for watching and I hope you have a nice day.