指针访问类私有成员

来源:互联网 发布:四川鹏业软件 编辑:程序博客网 时间:2024/04/29 04:28
#define _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 #include<iostream>    #include<algorithm>    using namespace std;class Base{public:int b;Base(int x) :a(x) { b = x + 1; }private:int a;virtual void func() { cout << "func\n"; }};int main(){Base one(1);//2.int* p = ((int*)&one + 1);cout << *((int*)&one + 1);//1cout << *p;//1return 0;}

1 0
原创粉丝点击