this pointer is present in _______________? object friend function main function member function code example
Example: this in c++
#include <iostream>
class Entity
{
public:
int x, y;
Entity(int x, int y)
{
Entity*const e = this;// is a ptr to the the new instance of class
//inside non const method this == Entity*const
//e->x = 5;
//e->y =6;
this->x = x;
this->y = x;
}
int GetX()const
{
const Entity* e = this;//inside const function this is = const Entity*
}
};
int main()
{
Entity e1(1,2);
}