OOP_5多态性.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
OOP_5多态性汇编

* 5.5 运行期类型识别(RTTI) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 3.Name Hiding(隐藏) Suppose that base class B has a nonvirtual method m and its derived class D also has a method m . D’s local method D::m is said to hide the inherited method B::m. Name hiding is particularly tricky(难以捉摸的) if the derived class’s method has a different signature than the base class’s method of the same name . * Error. The local D::m hides the inherited B::m. The method m is nonvirtual. The derived class has the same name method m(with a different signature ) 31 explicitly call B::m m(int) m() From B D * Name hiding can occur with virtual as well as nonvirtual method. In effect , name hiding occurs with virtual methods whenever a derived class virtual method fails to override the base class virtual method ( with a different signature ). * The method m is virtual. The derived class has the same name virtual method m(with a different signature ) For polymorphism to occur , there must be a virtual method with the same signature in each class. * 4. Name Sharing in C++ Programming(名字共享) Top-level functions with overloaded names . This is a convenience (便利) to programmers , who then can use one name to invoke many different function. Constructors with overloaded names . A class often has more than one constructor 。 Nonconstructors methods of the same class with the same name。 In a class hierarchy . For polymorphism to occur , the virtual methods must have the same signature (Name Overriding) When functions in a hierarchy share a name but not a signature , name hiding becomes a danger , So this name sharing be used with great caution(小心). 5.3 Name Overloading, Name Overriding, and Name Hiding * 5.4 Abstract Base Classes It is helpful if the

文档评论(0)

wyjy + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档