C++程序设计教程 第7讲:继承与派生
C++程序设计教程 第7讲: 继承与派生
引言 继承: inheritance 用现有的类建立新类,在新类中继承了现有类 的属性和行为,新类还可以对这些行为和属性 进行修饰。 现有的类--基类 Base class 新类--派生类 Derived class A A B ABC 基类A 派生类B 派生类C
C 引言 继承:inheritance 用现有的类建立新类,在新类中继承了现有类 的属性和行为,新类还可以对这些行为和属性 进行修饰。 现有的类 --- 基类 Base class 新类 --- 派生类 Derived class。 A B A B A 基类 A 派生类 B 派生类 C
基类和派生类 有关继承的例子 t Student CommuterStudent Residentstudent Shape> Circle/Triangle Rectangle Loan Carloan / HomelmprovementLoan MortgageLoan Employee Faculty Member /StaffMember Account> CheckingAccount SavingsAccount
基类和派生类 有关继承的例子: Student → CommuterStudent / ResidentStudent Shape → Circle / Triangle / Rectangle Loan → Carloan / HomeImprovementLoan / MortgageLoan Employee → FacultyMember / StaffMember Account → CheckingAccount / SavingsAccount
基类和派生类 继承的层次结构 CommunityMember Employee Student Faculty Staff Administrator Teacher
基类和派生类 继承的层次结构 CommunityMember Employee Student Faculty Staff Administrator Teacher
基类和派生类 继承的层次结构 Shape TwoDimShape ThreeDim Shape Circle Sphere Square Cube Triangle Tetrahedron
基类和派生类 继承的层次结构 Shape TwoDimShape ThreeDimShape Circle Square Triangle Sphere Cube Tetrahedron