- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
5类之继承性与派生类讲义
* * * * * * * * * * * 例 派生类构造函数的执行顺序 #include iostream.h class A { public: A( ) { a=0; coutDefault constructor called.aendl; } A(int i) { a=i; coutConstructor called.aendl; } ~A( ) { coutDestructor called.aendl; } void Print( ) { couta,; } int Geta( ) { return a; } private: int a; }; void main( ) { B bb[2]; bb[0]=B(7,8,9); bb[1]=B(12,13,14); for(int i=0;i2;i++) bb[i].Print(); } class B:public A { public: B( ) { b=0; coutDefault constructor called.bendl; } B(int i,int j,int k):A(i),aa(j) { b=k; coutConstructor called.bendl; } ~B( ) { coutDestructor called.bendl; } void Print( ) { A::Print( ); coutb,aa.Geta()endl; } private: int b; A aa; }; class B:public A { public: B( ) { b1=b2=0; } B(int i) { b1=0;b2=i; } B(int i,int j,int k):A(i),b1(j),b2(k) { } ~B( ) { coutIn B.\n; } void Print( ) { A::Print(); coutb1,b2,; } private: int b1,b2; }; 例 多层派生类构造函数和析构函数。 #include iostream.h class A { public: A( ) { a=0; } A(int i) { a=i; } ~A() { coutIn A.\n; } void Print() { couta,; } private: int a; }; void main( ) { C c1; C c2(10); C c3(10,20,30,40); c1.Print(); c2.Print(); c3.Print(); } class C:public B { public: C( ) { c=0; } C(int i) { c=i; } C(int i,int j,int k,int l ):B(i,j,k),c( l ) { } ~C() { coutIn C.\n; } void Print() { B::Print(); coutcendl; } private:
您可能关注的文档
最近下载
- 酒店管理【运营前厅】亚朵前台入职培训基础手册.docx
- 贵州省黔东南苗族侗族自治州2024-2025学年七年级上学期期末语文试题(解析版).docx VIP
- 2025年河北邯郸市下半年市直事业单位及大学生乡村医生专项计划公开招聘(统一招聘) 工作人员228名笔试参考题库附答案解析.docx VIP
- 8.3法治社会(教学设计)-高中政治统编版必修3.docx VIP
- 加油站大气污染物排放新国标方法验证-气液比.pdf VIP
- 论尼日利亚专利法律制度-毕业论文.doc VIP
- 2025年下半年河北邯郸市市直事业单位及大学生乡村医生专项计划招聘(统一招聘)228人笔试备考题库及答案解析.docx VIP
- 论尼日利亚专利法律制度-国际法专业论文.docx VIP
- 血液透析患者心理问题及护理对策.doc VIP
- 《中国流行音乐》课件.ppt VIP
文档评论(0)