多继承很容易用错,当需要将两个类组合成一个类时,你认为在什么情况下采用多继承?在什么情况下采用由一个类包容(委托)另一个类?谢谢大家能给点意见

解决方案 »

  1.   

    In MSDNTN016: Using C++ Multiple Inheritance with MFC
    This note describes how to use Multiple Inheritance (MI) with the Microsoft Foundation Classes.C++: Under the Hood
    Jan Gray
    March 1994Nested Class Declarations
    A class can be declared within the scope of another class. Such a class is called a “nested class.” Nested classes are considered to be within the scope of the enclosing class and are available for use within that scope. To refer to a nested class from a scope other than its immediate enclosing scope, you must use a fully qualified name.
    Nested classes can directly use names, type names, names of static members, and enumerators only from the enclosing class. To use names of other class members, you must use pointers, references, or object names.Access Privileges and Nested Classes
    Nesting a class within another class does not give special access privileges to member functions of the nested class. Similarly, member functions of the enclosing class have no special access to members of the nested class.For more information about access privileges, see Chapter 10, Member-Access Control.