学习本章之前需要 复习静态成员函数的知识点。
    静态成员函数和非静态成员函数出现同名,处理方式一致
    1:访问子类同名成员 直接访问即可。
    2:访问父类同名成员 需要加作用域。

    示例:

    1. #include<iostream>
    2. using namespace std;
    3. class Base
    4. {
    5. public:
    6. static int m_a;
    7. static void show()
    8. {
    9. cout<<"Base 函数的调用"<<endl;
    10. }
    11. static void show(int a)
    12. {
    13. cout<<"Base->函数的调用"<<endl;
    14. }
    15. };
    16. int Base::m_a=100;
    17. class son:public Base
    18. {
    19. public:
    20. static int m_a;
    21. static void show()
    22. {
    23. cout<<"son 函数的调用"<<endl;
    24. }
    25. };
    26. int son::m_a=200;
    27. //同名静态成员属性
    28. void test()
    29. {
    30. son p;
    31. cout<<"通过对象进行调用"<<endl;
    32. cout<<"son m_a="<<p.m_a<<endl;
    33. cout<<"Base m_a="<<p.Base::m_a<<endl;
    34. cout<<"通过类名进行调用"<<endl;
    35. cout<<"son ->m_a="<<son::m_a<<endl;
    36. //第一个::代表我要通过类名访问一个数据 第二个::代表访问父类作用域下访问m_a;
    37. cout<<"Base->m_a="<<son::Base::m_a<<endl;
    38. }
    39. //同名静态成员函数
    40. void test0()
    41. {
    42. son p;
    43. cout<<"通过对象进行同名静态成员函数调用"<<endl;
    44. p.show();
    45. p.Base::show();
    46. cout<<"通过类 进行同名静态成员函数调用"<<endl;
    47. son::show();
    48. son::Base::show();
    49. //如果子类中出现父类中同名静态成员函数,那么会隐藏父类中所有同名静态成员函数。
    50. son::Base::show(100);
    51. }
    52. int main()
    53. {
    54. test();
    55. test0();
    56. return 0;
    57. }

    网址:https://www.bilibili.com/video/BV1et411b73Z?p=132&spm_id_from=pageDriver