I just saw a post in which I found something I never saw before, in short here it is:
class A {
public:
int _x;
};
void foo(A *a_ptr, int *m_ptr)
{
cout << (*a_ptr).*m_ptr << endl; // here
}
int main()
{
A a;
a._x = 10;
foo(&a, &A::_x); // and here
}
How could it be done? Pass in &A::_x
, and later refer it using (*a_ptr).*m_ptr
?
I thought, &A::_x
will always refer to the same address, but different objects have different _x
, how could it be done?