O'Reilly logo

C++ Common Knowledge: Essential Intermediate Programming by Stephen C. Dewhurst

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

Item 15. Pointers to Class Members Are Not Pointers

It’s unfortunate that pointers to class members have the term “pointer” in their descriptions, because they don’t contain addresses and don’t behave like pointers.

The syntax for declaring a pointer to member is really not too horrible (if you’re already resigned to the declarator syntax for regular pointers):

int *ip; // pointer to an intint C::*pimC; // pointer to an int member of C

All you have to do is use classname::* rather than a plain * to indicate you’re referring to a member of classname. Otherwise, the syntax is the same as for a regular pointer declarator.

void *   *   *const* weird1;void *A::*B::*const* weird2;

The name weird1 has the type pointer to const pointer to pointer to ...

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