013_linuxC++之_派生类中权限的调整 012_LINUXC++之_类的继承定义

(一)在上一篇012_LINUXC++之_类的继承定义中我们知道在派生类中可以访问public和protectd中的数据

(二)那么我们就可以在派生类中将上面两个中的数据进行权限的修改

(三)程序

 1 #include <iostream>
 2 using namespace std;
 3 class Father{
 4 public:
 5         int test1;
 6 private:
 7         int test2;
 8 protected:
 9         int test3;
10 
11 };
12 
13 class Son:public Father{
14 public:
15     using Father::test3;    /*将test3修改成为public,那么外部就可以使用*/
16 
17 };
18 int main(int argc, char **argv)
19 
20 {
21     Son S;
22     S.test1 = 0;
23     S.test3 = 0;
24 }
View Code

(四)更改权限使用using

猜你喜欢

转载自www.cnblogs.com/luxiaoguogege/p/9693759.html
今日推荐