Bifalgorithm post
How can we use this keyword in C++ programming? Let's suppose you are having a class called car from which several objects can be created and this has private attribute called speed which cannot be directly accessed outside of this class. That's why we have to use public method called setSpeed. In this way of indirect access of attribute, here we are accessing attribute speed indirectly with the help of this public method called setSpeed which is a beautiful concept in object-oriented programming. And let's suppose you have created an object called Tata from this class car and you are setting a speed for this car called Tata. So you are passing speed here 180 and since the name of this speed which is in argument and the attribute of this object are same. So to avoid this conflict, when you use this keyboard, it will be treated as attribute of that object, not what we passed in argument.
How can we use this keyword in C++ programming? Let's suppose you are having a class called car from which several objects can be created and this has private…
Ideas in this flowchart
- Uso de 'this' en C++
- Clase 'car'
- Atributo privado 'speed'
- Método público 'setSpeed'
- Acceso indirecto a 'speed'
- Creación de objeto 'Tata'
- Conflicto de nombres
- Uso de 'this'
- Atributo del objeto