Pointer to a member (data or function member) of a class in C++

A pointer to a class member points to a member of a class. It provides an offset to an object of member’s class.

For Example:

class test {


cl(int x) { val=x; }

int y;

int double_y() { return y+y; }


int main()


int test::*d;

int (test::*f)();

test ob1(1), ob2(2);

d = &test::y;

f= &test::double_y;


Here *d is the data member pointer and *f is the function member pointer.

Leave a Reply