简单租房合同课件

上传人:bin****86 文档编号:55402787 上传时间:2018-09-28 格式:PPT 页数:34 大小:923.50KB
返回 下载 相关 举报
简单租房合同课件_第1页
第1页 / 共34页
简单租房合同课件_第2页
第2页 / 共34页
简单租房合同课件_第3页
第3页 / 共34页
简单租房合同课件_第4页
第4页 / 共34页
简单租房合同课件_第5页
第5页 / 共34页
点击查看更多>>
资源描述

《简单租房合同课件》由会员分享,可在线阅读,更多相关《简单租房合同课件(34页珍藏版)》请在金锄头文库上搜索。

1、Chapter 11 Inheritance and Polymorphism,11.1 Concept of Inheritance 11.2 Accessibility in Inheritance 11.3 Constructor/Destructor in Inheritance 11.4 Multiple Inheritance 11.5 Redefining Functions 11.6 Virtual Function and Polymorphism 11.7 Abstract Classes 11.8 Dynamic Casting,2,11.1 Concept of Inh

2、eritance (继承),The “is a” relationship Apple is a fruit Elephant is an animal Circle is a shape A is a B A has the characteristics/features/properties of BA inherits B Class A inherits class B,Inheritance can extend existing classes!,3,Class Inheritance,Syntax:,B,A,基类 父类 超类 Base Parent Super-Class,派生

3、类 子类 Derived-Class Child,class DerivedClass : acckeyword BaseClass;,class A: public B public: private: ;,B,A,4,Example of Inheritance,GeometricObject.h,GeometricObject.cpp,DerivedCircle.h,DerivedCircle.cpp,Rectangle.h,Rectangle.cpp,TestGeometricObject,Run,5,A Tip about Generic Programming(泛型编程),With

4、 inheritance, an object of a derived class can be used wherever an object of the base class is required This is a kind of GPGP permits writing common functions or types that differ only in the types operated on Template (模板) (in Chapter 15) is the main GP technique in C+,void showArea(GeometricObjec

5、t gb); Circle cl; Rectangle rt; showArea( cl); showArea(rt);,6,11.2 Accessibility in Inheritance,The protected Keyword A protected data field or function can be accessed by name in its derived classes,class B public:int i; protected:int j; private:int k; ;,class A: public B public:void display() cou

6、t i endl; cout j endl; cout k endl; ;,int main()A a;cout a.i endl; cout a.j endl; cout a.k radius = radius; ,Ever saw before?,Constructor Initializer!,class Action public: Action(int hr, int min, int sec) :time(hr, min, sec) private: Time time; ;,Object name!,Class name!,11,No-Arg Constructor in Bas

7、e Class,A constructor in a derived class must always invoke a constructor in its base class. If a base constructor is not invoked explicitly, the base classs no-arg constructor is invoked by default. For example,12,11.4 Multiple Inheritance,Type of Inheritance,Single (单重) Multiple(多重) Repeated(重复),1

8、3,Multiple Inheritance,Syntax:For example:,class DerivedClass: acckeyword BaseClass, acckeyword BaseClass ;,class CPolygon ;,class COutput ;,class CRectangle:public CPolygon, public COutput public: int area () return (width * height); ;,14,Constructor and Destructor Chaining,More than one constructo

9、r/destructor to invoke,A() A(),C() C(),ME() ME(),class A: public B. ;class ME: public A, public C.D d; ;,B() B(),D() D(),Invoking order of constructors: B, A, C, D, ME Invoking order of destructors: in reverse order,ChainingDemo,Run,15,11.5 Redefining Functions,A function of the base class may be re

10、defined(重新定义)in the derived class For example:,string GeometricObject:toString() return “Geometric object color “ + color + “ filled “ + (filled) ? “true“ : “false“); ,string Circle:toString() return “Geometric object color “ + color + “ filled “ + (filled) ? “true“ : “false“+“radius “+ radius); ,16

11、,Redefining vs. Overloading,17,Invoking Functions Redefined,To invoke the function defined in the derived class:circle1.toString(); To invoke the function defined in the base class:circle1.GeometricObject:toString();,Scope resolution operator (作用域解析运算符),18,11.6 Virtual Function and Polymorphism,What

12、 we want?,class HM public:void show()cout“Humann“; ;,class CN: public HM public:void show()cout“Chinesen“; ;,class CT: public CN public:void show()coutshow(); delete hm;hm = new CN();hm-show(); delete hm;hm = new CT();hm-show(); delete hm; ,Human Human Human,Human Chinese Cantonese,Polymorphism (多态)

13、,19,Polymorphism,Listing 11.9 to demonstrate polymorphismPolymorphism(多态) Also called dynamic binding (动态绑定) Two elements Virtual function (虚函数) Pointer of base class,Run,WhyPolymorphismDemo,Run,PolymorphismDemo,20,Virtual Functions,The function declared with the keyword “virtual”Overriding To redefine a virtual function in the derived class,class C public: virtual string toString() return “class C“; ;,class B: public C string toString() return “class B“; ;,

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > PPT模板库 > 其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号