Three ways of inheriting in object-oriented C + +

Source: Internet
Author: User
Tags access properties

Public inheritance
    • The access properties of the base class's public and protected members remain the same in the derived class, but the private members of the base class are not directly accessible.
    • member functions in derived classes can directly access public and protected members in the base class, but cannot access the private members of the base class directly.
    • Objects derived from a class can access only the public members of the base class.
Private inheritance
    • Both public and protected members of the base class appear in the derived class as private, but the private members of the base class are not directly accessible.
    • member functions in derived classes can directly access public and protected members in the base class, but cannot directly access the private members of the base class.
    • An object through a derived class cannot directly access any members in the base class.
Protect inheritance
    • Both public and protected members of the base class appear in the derived class as protected, but the private members of the base class are not directly accessible.
    • member functions in derived classes can directly access the public and protected members of the base class, but cannot directly access the private members of the base class.
    • An object through a derived class cannot directly access any members in the base class.

Inheritance type \ access mode

Public Protected Private
Public Public Protected Private
protected protected protected private
Private Private Private Private

Three ways of inheriting in object-oriented C + +

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.