How to gain Access to member variables of a class using void pointer but Not Object
Posted
by mahesh
on Stack Overflow
See other posts from Stack Overflow
or by mahesh
Published on 2009-07-10T04:19:22Z
Indexed on
2010/04/16
2:53 UTC
Read the original article
Hit count: 339
Hi,
I am trying to access member variables of a class without using object. please let me know how to go about.
class TestMem
{
int a;
int b;
public:
TestMem(){}
void TestMem1()
{
a = 10;
b = 20;
}
};
void (TestMem::*pMem)();
int main(int argc, char* argv[])
{
TestMem o1;
pMem = &(TestMem::TestMem1);
void *p = (void*)&pMem;
// How to access a & b member variables using variable p
getch();
return 0;
}
© Stack Overflow or respective owner