It seems the your question is about pointers of pointer-to-data-member type. In C++ there are also pointers of pointer-to-member-function type. The two have something in common at some abstract level, but otherwise they are different.
Pointer of pointer-to-data-member type is applicable to any instance of the class. An ordinary pointer always points to a member of a specific instance of the class. Pointer of pointer-to-data-member type is a higher level implementation of the idea of "run-time offset" from the beginning of a class object. It is a relative pointer. In that way it is completely different thing from ordinary pointers, which are absolute pointers.
To illustrate that with an example, let's say you have an array of classes with three members of the same type x
, y
and z
struct Point { int x, y, z; };
Point point_array[N];
and you need to set all members with the same name to 0
in the entire array, without changing any other members. Here's how you can do it using a pointer of pointer-to-data-member type
void zero_members(Point points[], int n, int Point::*m) {
for (int i = 0; i < n; ++i)
points[i].*m = 0;
}
Now, by using this function you can do
zero_members(point_array, N, &Point::x);
to set all x
s to zero. Or you can do
zero_members(point_array, N, &Point::y);
to set all y
s to zero. You do can all this with a single function, and what's also important, the member selection is performed by a run-time parameter (as opposed to a compile-time one).
You cannot do something like this with ordinary pointers. In fact, you can't do it in any other way.