can anyone plz tell me where the 'this' pointer points to ?
I mean :
if 'b' be a object of a class and 'f' be one of the class functions , when we write b.f() -->
"this" pointer , points to 'b'( object of a class ) or points to 'f' (function of a class ) ?
tnx
The "this" pointer is only applicable within a method function. In that case "this" refers to the object the method function is being called from. For example,
Code:
class C
{
int x;
public:
void f() { this->x = 40; }
};
and this->x refers to the variable x of some particular object of class C. What "this" points to his not determined by dynamic execution but by scope. So you can write
Code:
class D
{
C c;
int y;
public:
void f() { c.f(); this->y = 100; }
};
D d;
d.f();
and "this" in D::f's context points &d during the execution of d.f(), even though in c.f this points to &d.c