struct C {
C( int i ) : data(i) { }
int data;
};
template <class T> void f( T C::* ) // <== What does this parameter mean ?
{ }
int main()
{
f( &C::data ); // how come you got the address of a non-static member
}
I was thinking of it as an unnamed pointer, am i right ?
&C::data is not the address of a non-static member, it's a pointer to member. int C::* is its type
If you have an object of type C or derived from C, you can use that pointer to access the member:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
struct C {
C( int i ) : data(i) { }
int data;
};
int main()
{
int C::* p = &C::data; // pointer to member
C obj1(7), obj2(-1);
std::cout << obj1.*p << ' ' << obj2.*p << '\n';
}