O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The this Pointer

Every class member function has a hidden parameter: the this pointer. this points to the individual object. Therefore, in each call to GetAge() or SetAge(), the this pointer for the object is included as a hidden parameter.

The job of the this pointer is to point to the individual object whose method has been invoked. Usually, you don't need this; you just call methods and set member variables. Occasionally, however, you'll need to access the object itself (perhaps to return a pointer to the current object). It is at that point that the this pointer becomes so helpful.

Normally, you don't need to use the this pointer to access the member variables of an object from within methods of that object. You can, however, explicitly call ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required