C++中使用指针访问类私有变量

来源:互联网 发布:手机迅雷打开php文件 编辑:程序博客网 时间:2024/06/06 14:25

上代码

#include <iostream>class A{        private:                int value;        public:        int getValue()        {                return this->value;        }};int main(){        A *a = new A();        *((int *)a) = 100;        std::cout << a->getValue() << std::endl;        delete a;}
可以修改value的值。

0 0
原创粉丝点击