Skip to main content

Command Palette

Search for a command to run...

this in object

Published
1 min readView as Markdown

🔹 Easy Definition:

In C++, this is 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:

this means this object.”

More from this blog

Amit singh's blog

235 posts