Friday, 17 April 2015

Pointer to Class Members


#include <iostream.h>
Class X
{
int y;

public:
int a,b;
int init(int z)
{
a = z;
return z;
}
};
void main()
{
X obj;
Int X::*ip;
ip = &X::a;
obj.*ip = 10;
cout<<”A in object, after obj.*ip”;
cout<<obj.*ip;
X *pobj;
Pobj = &obj;
Pobj->*ip = 20;
Cout<<”A in object, after pobj->*ip”;
Cout<<”pointer to member function\n”;
Int (X::*ptr)(int);
ptr = &X::init;
(obj.*ptr)(5);
(pobj->*ptr)(6);
}

No comments:

Post a Comment