- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
9.OOPamp;amp;ADTsIntroductiontoInheritance.ppt
9. OOP ADTs: Introduction to Inheritance Constructors and Inheritance Consider Employees constructor // Explicit-Value Constructor inline Employee::Employee long id, string last, string first, char initial, int dept myIdNum id; myLastName last; myFirstName first; myMiddleInitial initial; myDeptCode dept; A derived class can use a member-initialization-list to call the base-class constructor to initialize the inherited data members — easier than writing it from scratch. // Definition of SalariedEmployee explicit-value constructorinline SalariedEmployee::SalariedEmployee long id, string last, string first, char initial, int dept, double sal From the derived class constructor, pass the id number, last name, first name, middle initial and dept. code to the Employee constructor to initialize those members. mySalary sal; SalariedEmployee then initializes only its own local member s . : Employee id, last, first, initial, dept * Read Chap. 12 A. Inheritance, OOD, and OOP §12.1 12.2 A major objective of OOP: writing reusable code to avoid re-inventing the wheel . Ways to do this in C++: Encapsulate code within functions Build classes Store classes and functions in separately-compiled libraries Convert functions into type-parameterized function templates Convert classes into type-parameterized class templates An additional approach that distinguishes OOP from the others: Inheritance: Define one class derived class in terms of another base class, reusing the data members and function members of the base class. Example: Suppose a problem requires stack operations not provided in our stack class — e.g., max , min Ways to Approach this: #1: Add function members to the Stack class that implement the new operations. Bad: This can easily mess up a tested, operational class, creating problems for other client programs. new operations push , pop , ... myTop, ... new data members Stack class #2: An adapter approach:
您可能关注的文档
最近下载
- 2025年新外研版英语3年级上册全册教学课件.pptx
- 信息安全管理手册+适用性声明+程序文件全套(27001 2022版).doc
- 新能源汽车维修手册 HA-HAS-hev.pdf VIP
- 关键对话_让沟通更高效.pdf VIP
- 05G359-3悬挂运输设备轨道标准图集.pdf VIP
- 英语课堂游戏教学技巧.docx VIP
- (2025年)村干部考试试题(答案).docx VIP
- 2025新版三下英语Unit 1 Meeting new people单元整体教学设计.docx VIP
- 市政工程公司一级安全教育内容.docx VIP
- VDA6.3-2023版过程审核-各部门准备资料及审核和应审方法.xlsx VIP
文档评论(0)