Effective C + + 6. Inheritance and object-oriented design

Source: Internet
Author: User

//clause 32: Determine your public inheritance mold out is-a relationship//1.public inheritance implies a is-a relationship, and the methods that apply to the base class can be used on derived classes. //Article 33: Avoid hiding the inherited name//1. In the public inheritance system, the relationship between the derived class and the base class is is-a, so the non-virtual functions of the base class should not be hidden in the derived class. //2. In order to overload a non-virtual function of a base class in a derived class, you can use a using declaration or display a non-virtual function that calls the base class in a function of a derived class. //Article 34: Differentiating between interface inheritance and implementation inheritance//1. Interface inheritance differs from implementation inheritance. Under the public inheritance system, derived classes always inherit the interface of the base class. //2. Pure virtual functions Specify interface inheritance only. //3. The general virtual function specifies interface inheritance and default implementation inheritance. //4. Non-virtual functions specify interface inheritance and enforce inheritance. (as described in clause 33, do not hide non-virtual functions of the base class in a derived class in public inheritance)//Article 38: By compounding the mold out of the has-a or according to something to achieve//clause 39: Use private inheritance wisely and cautiously//1. Private inheritance is highly likely to be an orthodox design strategy when one of the classes needs to access the protected members of another class, or when a virtual function needs to be redefined, when confronted with two classes that do not have a is-a relationship. //2. For an empty class, the compiler typically inserts a char into its memory. When a class private inherits an empty class, the class has other data members, and the empty class char does not occupy the space of the derived class. 

Effective C + + 6. Inheritance and object-oriented design

Related Article

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.