正在加载图片...
Access control(cont class X class y public public int mf10 int m1. int mf20[ return mf30; 1 int get m20i return m2; 1 private: void set m2(int xim2=X;1 int mf30 private: int m2. }x; }y; void main( void maino x.mf10; llyes y. m1++; //Not suggested! Direct Xmf30;∥Eror! Private access data members member can't be accessed out yset_m2(1);/Suggested! The of the class data mem ber is accessed under controlAccess control (cont.) class X { public: int mf1(); int mf2() { return mf3(); } private: int mf3(); } x; void main() { x.mf1(); //yes x.mf3(); //Error! Private member can’t be accessed out of the class } class Y { public: int _m1; int get_m2() { return _m2;} void set_m2(int x) { _m2 = x;} private: int _m2; } y; void main() { y._m1++; //Not suggested! Direct access data members y.set_m2(1); //Suggested! The data member is accessed under control }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有