this in object
🔹 Easy Definition:
In C++,
thisis a special pointer inside a class that always points to the current object — the one that is calling the function.
🔹 Think like this:
If you have many objects of the same class,this helps the function know which object it is working with right now.
🔹 Example:
class Student {
public:
void show() {
cout << "This points to: " << this << endl;
}
};
int main() {
Student s1, s2;
s1.show(); // 'this' points to s1
s2.show(); // 'this' points to s2
}
👉 When s1 calls show(),this = address of s1.
When s2 calls show(),this = address of s2.
🧠 In short:
this= the address of the object that called the function.
Or simply:
“
thismeans this object.”