Detail explanation about "this"

example: SetOwner(this);
explanation about (this)

It is an implicit argument that can be passed to all the member functions for referring to the invoking object. So in UE if you use it in the player controller for example, it refer to this Player Controller where you write the code. There is exception and you can find more detailed documentation online!

1 Like

To put the above into code.

class Example
{
    void Foo();
};

int main()
{
    Example E;
    E.Foo();
}

To the compiler the above looks more like

class Example
{
};

void Foo(Example*);

int main()
{
    Example E;
    Foo(&E);
}

And that’s what this is. A pointer to the instance executing that code.

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms