I think &(foo.bar) is just a regular variable pointer. When we say "member pointer", we mean something like &(FooClass::bar) , without specifying any objects! Note that this value can actually be computed at compile time and can be used, for example. in templates.
Member pointers have really strange syntax.
Try running the following code:
#include <stdio.h> class FooClass { public: int bar; int bar2; FooClass() : bar(0), bar2(0) {} }; int main() { //Showing what member pointers actually hold: int FooClass::* barPtr=&FooClass::bar; int FooClass::* bar2Ptr=&FooClass::bar2; printf("barPtr=%p\nbar2Ptr=%p\n",barPtr,bar2Ptr); //Showing how to use them: FooClass foo; foo.*bar2Ptr=42; printf("foo={%d,%d}\n",foo.bar,foo.bar2); }
You will get the result:
barPtr=0x0 bar2Ptr=0x4 foo={0,42}
As you can see, both values ββhave a member offset from the start of the class. They can be calculated even if you donβt know which object you are working on.
But if you want to dereference them, you must provide an object - what the operator does .* .
source share