1、多重继承的歧义性问题 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; //error mp.checkOut(); // ambiguous! which checkOut? //right mp.BorrowableItem::checkOut(); // ah, that checkOut... 2、最顶层基类数据被重复复制的问题 class File { ... }; class InputFile: public File { ... }; class OutputFile: public File { ... }; class IOFile: public InputFile, public OutputFile { ... }; //C++ 它的缺省方式是执行复制。如果那不是你想要的,使用 virtual inheritance(虚拟继承) class File { ... }; class InputFile: virtual public File { ... }; class OutputFile: virtual public File { ... }; class IOFile: public InputFile, public OutputFile { ... }; 3、多重继承的确有正当用途。其中一个情节涉及"public继承某个Interface class"和"private继承某个协助实现的class"的两点相组合。 class IPerson { // this class specifies the public: // interface to be implemented virtual ~IPerson(); virtual std::string name() const = 0; virtual std::string birthDate() const = 0; }; class DatabaseID { ... }; // used below; details are // unimportant class PersonInfo { // this class has functions public: // useful in implementing explicit PersonInfo(DatabaseID pid); // the IPerson interface virtual ~PersonInfo(); virtual const char * theName() const; virtual const char * theBirthDate() const; virtual const char * valueDelimOpen() const; virtual const char * valueDelimClose() const; ... }; class CPerson: public IPerson, private PersonInfo { // note use of MI public: explicit CPerson( DatabaseID pid): PersonInfo(pid) {} virtual std::string name() const // implementations { return PersonInfo::theName(); } // of the required // IPerson member virtual std::string birthDate() const // functions { return PersonInfo::theBirthDate(); } private: // redefinitions of const char * valueDelimOpen() const { return ""; } // inherited virtual const char * valueDelimClose() const { return ""; } // delimiter }; // functions