这应该算是C++的一个不足吧,C++是优秀的编程语言,但不是完美的。
#include<iostream.h> class A { public : A():_personalA(100){ cout << " this is construction of A " << endl ; print( ); } ~A(){ cout << " this is destruction of A " << endl ; print() ; } int & GetA() { return _personalA ; } void print(){ cout << " this is print() of class A the values of _personalA is : " << _personalA << endl ; } private : int _personalA ; }; int main() { A a ; int &num = a.GetA(); a.print(); cout << num << endl ; cout << " please input the values of _personalA . Attempt to modify the provate variables " << endl; cin >> num ; a.print(); cout << num << endl ;; return 0 ; }C++中私有变量的值想怎么改就怎么改
最新推荐文章于 2024-08-14 22:29:49 发布