When using a pointer-to-member (AKA point-to-point or star-arrow) to access a class member, we can use the following syntax:
A * pa; int A::*ptm2 = &A::n; std::cout << "pa->*ptm: " << pa->*ptm << '\n';
My question is how the &A::n operator works?
In the above example, n is a variable. If instead of a member variable, n was a function (and we specified a member-pointer-function instead of a member-pointer), I can assume that since the functions of the class can be static (see the Nemo comment), we could find the address of a class function via &A::some_function . But how can we get the address of a non-static member of a class through class resolution? This is even more confusing when I print the value &A::n , because the output is just 1 .
c ++ scope pointers class pointer-to-member
user2141130 Jul 19 '13 at 21:46 2013-07-19 21:46
source share