基本语法
    class A:public B;

    A类被称为子类或派生类
    B类被称为父类或基类

    派生类中的成员,包含两大部分:
    一类是从基类继承过来的,一类是自己增加的成员。
    从基类继承过来的表现其共性,而新增的成员体现了其特性

    1. //继承实现页面
    2. //继承的好处:减少重复代码的实现
    3. class BasePage
    4. {
    5. public:
    6. void header()
    7. {
    8. cout << "首页、公开课、登录、注册....(公共头部)" << endl;
    9. }
    10. void footer()
    11. {
    12. cout << "帮助中心、交流合作、站内地图...(公共底部)" << endl;
    13. }
    14. void left()
    15. {
    16. cout << "Java、python、C++...(公共分类列表)" << endl;
    17. }
    18. };
    19. class Java :public BasePage
    20. {
    21. public:
    22. void content()
    23. {
    24. cout << "Java学科视频" << endl;
    25. }
    26. };
    27. class Python :public BasePage
    28. {
    29. public:
    30. void content()
    31. {
    32. cout << "Python学科视频" << endl;
    33. }
    34. };
    35. class CPP :public BasePage
    36. {
    37. public:
    38. void content()
    39. {
    40. cout << "C++学科视频" << endl;
    41. }
    42. };
    43. void test01()
    44. {
    45. cout << "Java下载视频页面如下:" << endl;
    46. Java ja;
    47. ja.header();
    48. ja.footer();
    49. ja.left();
    50. ja.content();
    51. cout << "------------------------------------" << endl;
    52. cout << "Python下载视频页面如下:" << endl;
    53. Python py;
    54. py.header();
    55. py.footer();
    56. py.left();
    57. py.content();
    58. cout << "------------------------------------" << endl;
    59. cout << "CPP下载视频页面如下:" << endl;
    60. CPP cpp;
    61. cpp.header();
    62. cpp.footer();
    63. cpp.left();
    64. cpp.content();
    65. }
    66. int main()
    67. {
    68. test01();
    69. system("pause");
    70. return 0;
    71. }