C++ this Pointer
The 'this pointer' is a variable which is used to access the address of the class itself.
The ‘this’ refers to the current instance of the class. It is helpful to refer the current class instance variable.
Example:
#include <iostream>
using namespace std;
class Rectangle{
private:
int l,b;
public:
Rectangle(int l,int b)
{
this->l=l;
this->b=b;
}
void show_data()
{
cout << "Area of Rectangle: " << l*b << endl;
}
};
int main(){
Rectangle r1(5,4);
r1.show_data();
return 0;
}
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.