C ++ class Access Control (public/protected/private)

Source: Internet
Author: User
Tags types of functions

Summary of public, protected, and private access labels in C ++
First, the access range of the private, public, and protected access labels.Private: It can only be accessed by 1. functions in this class, 2. Other functions. Cannot be accessed by any other user, nor can the object of this class be accessed.
Protected: it can be accessed by 1. functions in this class, 2. Sub-class functions, and 3. Its membership functions. But cannot be accessed by objects of this class.
Public: it can be accessed by 1. functions in this class, 2. Sub-class functions, 3. Its friends functions, or 4. objects in this class. Note: There are three types of functions: normal non-member functions set as friends, member functions of other classes set as friends, and all member functions in the friends class.

Second, the method property changes after the class is inherited.Private attributes cannot be inherited.
Using private inheritance, the protected and public attributes of the parent class are changed to private in the subclass;
Using protected inheritance, the protected and public attributes of the parent class are changed to protected in the subclass;
Use public inheritance. The protected and public attributes in the parent class are not changed. See the following: public: protected: private:
Public inherits from public protected and is unavailable.
Protected inherits protected. protected is unavailable.
Private inherits private unavailability
Protected inheritance and private inheritance can reduce access permissions.

This article is from the "going straight to" blog, please be sure to keep this source http://cnmtjp.blog.51cto.com/204390/36548

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.