Mega Code Archive
Assign the address of a public member of an object to a pointer and then access that member by using the pointer
#include
using namespace std;
class cl {
public:
int i;
cl(int j) { i=j; }
};
int main()
{
cl ob(1);
int *p;
p = &ob.i; // get address of ob.i
cout << *p; // access ob.i via p
return 0;
}