#include<iostream.h>

#include<conio.h>

class Ptr

{

int a,b;

public:

void set(int m, int n)

{

a=m;

b=n;

}

friend int sum(Ptr p);

};

int sum(Ptr ob)

{

int Ptr::* pa=&Ptr::a;

int Ptr::* pb=&Ptr::b;

Ptr *p=&ob;

int s=ob.*pa+p->*pb;

return s;

}

void main()

{

Ptr n;

clrscr();

cout<<"\n C++ program on Pointer to members: " << endl;

void (Ptr:: *pf) (int, int)=&Ptr::set;

(n.*pf)(25,45);

cout<<"\n sum= "<< sum(n) << endl;

Ptr *ob=&n;

(ob->*pf) (100,50);

cout<<"\n sum= "<< sum(n) << endl;

getch();

}

output:

C++ program on Pointer to members: 

sum= 70

sum=150