测试...外部指针访问private

 

 

 

 1 #include<iostream>
 2 
 3 using namespace std;
 4 
 5 
 6 class A{
 7 public:
 8     int* getPointer(){
 9         return &m;
10     }
11     void out(){
12         cout<<"m = "<<m<<endl;
13     }
14 private:
15     int m;    
16     
17 };
18 
19 int main(){
20     int *p = nullptr;
21     A a;
22     
23     p = a.getPointer();
24     
25     *p = 3;
26     
27     
28     a.out();
29 } 

 

posted @ 2016-01-20 01:42  Agravity  阅读(160)  评论(0编辑  收藏  举报