C++ Pointer
Pointer
Uses of this
- The this pointer is useful when operators are overloaded.
- The this pointer is useful when the member function tries to find out the address of the object of which it is a member.
class Where
{
char array[10];
public:
void reveal ( ) { cout<<”\nMy objects address is “<<this<<endl; }
};
void main ( )
{
Where w1, w2, w3;
w1.reveal ( );
w2.reveal ( );
w3.reveal ( );
}
{
char array[10];
public:
void reveal ( ) { cout<<”\nMy objects address is “<<this<<endl; }
};
void main ( )
{
Where w1, w2, w3;
w1.reveal ( );
w2.reveal ( );
w3.reveal ( );
}
Restrictions
- First, friend functions are not members of a class and, therefore, are not passed a this pointer.
- Second, static member functions do not have a this pointer.

No comments:
Post a Comment