How to gain Access to member variables of a class using void pointer but Not Object

后端 未结 6 1183
暖寄归人
暖寄归人 2021-01-24 21:29

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:
    Tes         


        
6条回答
  •  日久生厌
    2021-01-24 22:06

    Short answer: You can't.

    Long answer: You can, but it's highly implementation dependent. If you dump the memory you find at *p you'll see, somewhere around there, what you're looking for - a and b. But you will very likely also see some other stuff. What that stuff is, what it means, how big it is (and by implication where a and b actually live) is implementation dependent.

提交回复
热议问题