32. c ++ primer 4th notes, multiple inheritance and virtual functions

Source: Internet
Author: User

1. The class can be used as the base class of Multi-inheritance only after being defined. The base class constructor is called in the order of occurrence in the derived list.

2. In multi-inheritance, the pointer or reference of a derived class can be converted to a pointer or reference of any base class.

3. When a class inherits from multiple base classes, there is no implicit relationship between the base classes and one base class pointer is not allowed to access members of other base classes.

4. Under virtual inheritance, for a given virtual base class, no matter how many times the class appears as a virtual base class in the derived hierarchy, only one shared base class sub-object is inherited.

5. the instance of a specific derived class has a higher priority than the shared virtual base class instance.

6. In virtual derivation, the constructor of the lowest-layer derived class initializes the virtual base class.

7. No matter where the virtual base class appears in the inheritance level, the virtual base class is always constructed before the non-virtual base class is constructed.

8,Generally, the base class should be constructed in the order specified in the derived list (directly or indirectly )., The derived class constructor should explicitly initialize each base class through the constructor initialization list. The order of the base classes in the initialization list of the constructor does not affect the order of the base classes. In virtual inheritance, the virtual base class is constructed before any other base class. Only the lowest-layer derived type can initialize the virtual base class, and the list of base class constructors in the intermediate base class is ignored.

9. Classes inherited by virtual keywords are called virtual base classes. The derived class of the lowest layer should contain the initialization type of all its virtual parent classes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.