C ++ Review and other inherited Access Control

Source: Internet
Author: User
I. c ++ inheritance

1. class inheritance is a mechanism provided in object-oriented programming. It allows programmers to define more specific and detailed classes on the basis of saving the features of the original classes. (Can be associated with reality: parents and children)

2. In C ++ class inheritance, a derived class can be derived from one base class or multiple base classes. Inheritance derived from a base class is called single inheritance. Inheritance derived from multiple base classes is called multi-inheritance.

3. class inheritance methods in C ++ include public, protected, and private.

4. Note: If the keyword of the inheritance mode is not displayed, the default value of the system is private ).

Ii. Access Control

The following describes "Access Control ". The "access" here comes from two aspects:

1. The new member in the derived class accesses the inherited member from the base class;

2. The object of the derived class accesses the inherited members of the base class.

(1) Public (Public inheritance)

The public members of the base class and the access attributes of the protected members remain unchanged in the derived class, while private members of the base class cannot access the base class directly.

1. Add a member to a derived class

You can directly access the public and protected members inherited from the base class)

2. Object of the derived class

Only public members inherited from the base class can be accessed directly)

(2) Protected)

Both the public and protected members of the base class appear in the derived class as protected members, and Private Members of the base class cannot directly access the base class.

1. Add a member to a derived class

You can directly access the public and protected members inherited from the base class)

2. Object of the derived class

You cannot directly access any type of members of the base class.

(3) Private (private inheritance)

Both the public and protected members of the base class appear in the derived class as private members, and the Private Members of the base class cannot be directly accessed.

1. Add a member to a derived class

You can directly access the public and protected members inherited from the base class)

2. Object of the derived class

You cannot directly access any type of members of the base class.

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.