Wise and prudent use of private inheritance

Source: Internet
Author: User
ArticleDirectory
  • Wise and prudent use of private inheritance (use private inheritance judicious .)
  1. Wise and prudent use of private inheritance (use private inheritance judicious .)
  2. Two rules inherited by private:
  3. 1. the compiler will not convert a derived class to baseclass, but it can display the conversion. That is, the relationship between them is not-.
  4. 2. All members and methods inherited from the base class will be changed to private attributes. That is, it only inherits the implementation and does not integrate interfaces.
  5. Private inheritance means "Implement Based on something". It conflicts with compound and uses compound as much as possible.
  6. Remember:
  7. 1. Private inheritance means "Implement Based on something", which is generally lower than the combination level. However, this design is reasonable only when the derived class needs to access the protected member of baseclass, or when it needs to redefine the inherited virtual function. Otherwise, use compound as much as possible.
  8. 2. Unlike composite, private inheritance can be used to find out the empty base optimization. This is intended for "minimal object size"ProgramLibrary developers may be important.

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.