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 }