触及 multiple inheritance (mi)(多继承)的时候,c++ 社区就会鲜明地分裂为两个基本的阵营。一个阵营认为如果 single inheritance (si)(单继承)是有好处的,multiple inheritance(多继承)一定更有好处。另一个阵营认为 single inheritance(单继承)有好处,但是多继承引起的麻烦使它得不偿失。在本文中,我们的主要目的是理解在 mi 问题上的这两种看法。
首要的事情之一是要承认当将 mi 引入设计领域时,就有可能从多于一个的 base class(基类)中继承相同的名字(例如,函数,typedef,等等)。这就为歧义性提供了新的时机。例如:
| class borrowableitem { // something a library lets you borrow public: void checkout(); // check the item out from the library .. }; class electronicgadget { private: bool checkout() const; // perform self-test, return whether ... // test succeeds }; class mp3player: // note mi here public borrowableitem, // (some libraries loan mp3 players) public electronicgadget { ... }; // class definition is unimportant mp3player mp; mp.checkout(); // ambiguous! which checkout? |
| mp.borrowableitem::checkout(); // ah, that checkout... |
| class file { ... }; class inputfile: public file { ... }; class outputfile: public file { ... }; class iofile: public inputfile, public outputfile { ... }; |
关键字 本文所属关键字
相关 与本文相关文章
分类 所有文章关键字导航源码编程相关Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏 操作系统/服务器相关Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器 标准 网站致力的规范 |