- 0
- 0
- 约1.29万字
- 约 32页
- 2021-11-30 发布于安徽
- 举报
* In principle, every member of a base class is inherited by a derived class Including public and protected members However, there are exceptions for constructor and destructor operator=() member (discuss later) Friends (discuss later) Since all these functions are class-specific §8.4 Constructors in Derived Classes * The constructors of a base class are not inherited How to initialize the data fields inherited from the base class? By calling base class constructors from the constructors of the derived classes Argument passing mechanism A (Except constructors ) B Constructor of Base * Calling Constructor of Base derived-constructor (type1 p1, type2 p2, …, typn pn, …): base1-constructor(p1), base2-constructor(p2){ //body of derived constructor; data1 = pn; } * No-Arg Constructor in Base 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 class’s no-arg constructor is invoked by default. For example, * Multiple Inheritance Base classes are constructed in the order in which they are declared Multilevel Inheritanc Constructors are executed in the order of inheritance Virtual Base Class Invoked before any non-virtual base classes If there are multiple virtual base classes, they are invoked in the order in which they are declared Order of Execution * Example More than one constructor/destructor to invoke B() ~B() C() ~C() ME() ~ME() class A {//…}; class X {//…}; class B: public A, virtual public X{//…}; class C: virtual public X{//…}; class ME: public B, public C{//…}; A() ~A() X() ~X() Invoking order of constructors: X, A, B, C, ME Invoking order of destructors: in reverse order Object Data Field The data field of a class is a an object * class alpha{ …}; class beta{ …}; class gamma{ …}; alpha a; beta b; …. }; How to initialize them? * Class objects can be initialized either in the constructor
您可能关注的文档
- 高等数学课件:9-7常系数线性微分方程组.ppt
- 高等数学课件:10.1向量及其运算(1-30).ppt
- 高等数学课件:10.2 空间直角坐标系与向量代数(1-24).ppt
- 高等数学课件:10.3 平面与直线.ppt
- 高等数学课件:10.4.1曲面及其方程.ppt
- 高等数学课件:10.4.2二次曲面.ppt
- 高等数学课件:10.5向量函数 空间曲线.ppt
- 高等数学课件:10-1 收敛原理与数项级数.ppt
- 高等数学课件:10-2 正项级数.ppt
- 高等数学课件:10-3任意项级数.ppt
- 山西省临汾市统编版六年级下册期末考试道德与法治试卷【含答案】.pdf
- 山西省临汾市洪洞县统编版六年级下册期末学业质量检测道德与法治试卷【含答案】.pdf
- 山西省晋中市太谷县统编版六年级下册期末学业水平质量监测道德与法治试卷【含答案】.pdf
- 山西省临汾市蒲县统编版六年级下册期末考试道德与法治试卷【含答案】.pdf
- 山西省晋中市祁县统编版六年级下册期末检测道德与法治试卷【含答案】.pdf
- 山西省大同市新荣区统编版六年级下册期末考试道德与法治试卷【含答案】.pdf
- 山西省大同市浑源县统编版六年级下册期末考试道德与法治试卷【含答案】.pdf
- 重庆市忠县统编版六年级下册期末考试道德与法治试卷【含答案】.pdf
- 重庆市潼南区统编版六年级下册期末质量监测道德与法治试卷【含答案】.pdf
- 重庆市铜梁区统编版六年级下册期末考试道德与法治试卷【含答案】.pdf
原创力文档

文档评论(0)