1 #include <iostream>
2 #include <string>
3 using namespace std;
4
5 class Base
6 {
7 public:
8 Base()
9 {
10 m_A = 100;
11 }
12 void func()
13 {
14 cout << "Base -func()调用" << endl;
15 }
16 int m_A;
17
18 void func(int a)
19 {
20 cout << "Base -func(int a)调用" << endl;
21 }
22
23
24 };
25
26 class Son : public Base
27 {
28 public:
29 Son()
30 {
31 m_A = 200;
32 }
33
34 void func()
35 {
36 cout << "Son -func()调用" << endl;
37 }
38
39 void func(int a)
40 {
41 cout << "Son -func(int a)调用" << endl;
42 }
43
44
45 int m_A;
46 };
47
48 //同名成员属性处理
49 void test01()
50 {
51 Son s;
52 cout << "Son m_A= " << s.m_A << endl;
53 //Base b;
54 //如果通过子类对象 访问到父类中的同名对象 要在子类后面加 父类的作用域
55 cout << "Base m_A= " << s.Base::m_A << endl;
56 //cout << "Base m_A= " << b.m_A << endl;
57 }
58
59 //同名成员函数处理
60 void test02()
61 {
62 Son s;
63 s.func(); //直接调用的是: 子类用的同名成员
64
65 //如何调用父类中的同名函数
66 s.Base::func();
67
68 //如果子类出现和父类中的同名的成员函数 子类的同名成员会隐藏掉
69 //父类中所有的同名成员函数
70
71 //如果想访问到父类中被隐藏的同名成员函数 需要加作用域
72 s.func(100);
73 s.Base::func(200);
74
75 }
76 int main()
77 {
78
79 //test01();
80 test02();
81
82 system("pause");
83
84 return 0;
85
86 }

最新文章

  1. windows下node环境配置
  2. java.lang.Class
  3. Winform 基本属性
  4. JSon_零基础_007_将JSon格式的&quot;数组&quot;字符串转换为Java对象&quot;数组&quot;
  5. Codeigniter 集成sphinx搜索 这里采用的是coreseek中文搜索引擎,具体安装请参考官方网站
  6. Javascript中的Keycode值列表
  7. 《C++ primer》--第1,2章小结
  8. 第十三章、学习 Shell Scripts 善用判断式
  9. careercup-树与图 4.8
  10. angularjs图片上传后不刷新的解决办法
  11. HDU2673:shǎ崽 OrOrOrOrz
  12. 第四弹:overfeat
  13. JS中new的自定义实现创建实例对象
  14. 无需超级用户mpi多机执行
  15. 五道java小题,补更四道java小题
  16. Python web框架对比
  17. php(curl请求)测试接口案例
  18. Node.js读取文件内容并返回值(非异步)
  19. android windows的一些item属性
  20. TensorRT简介-转载

热门文章

  1. 阿里云中quick bi用地图分析数据时维度需转换为地理区域类型
  2. Linux-Samba服务
  3. SpringBoot集成logback后访问日志端点
  4. 详解Docker 端口映射与容器互联
  5. CG-CTF WxyVM2
  6. js定时器中引用的外部函数如何传递参数
  7. 性能基准DevOps之如何提升脚本执行效率
  8. Linux | 搜索命令
  9. JUnit5依赖注入与测试接口
  10. 「CF559E」 Gerald and Path