C ++ access restriction: classic interpretation of Private Public protect

Source: Internet
Author: User

 

Public means that all members declared after it can be retrieved from all users.
Private means that no one except the creator of this type and the internal member functions of the class can access these members.
Protect is similar to private. There is only one difference: the inherited structure can access the protected member, but cannot access the private member.

========================================================== =====

 

Public has a good affinity,
Protect is only good for acquaintances,
Private is private.
But they are triplets.
Class is their father.

========================================================== ====

 

Public: the restroom in the public restroom, which can be used by everyone.
Protect: the restroom in your home can be used as long as it is regarded as your own family.
PRIVATE: You are an infectious disease person. You cannot use your own toilet or your own toilet.

Friend can access private.
Friend is like if he is your boyfriend or girlfriend, he can make an exception, but this exposes your privacy and should not be promoted.

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.