Publc protected private)

Source: Internet
Author: User

A member of the class can be: private protected public
1. If a member is private, its name can only be used by the member functions and Friends of the class in which it is declared
2. If a member is protected, its name can only be used by the member functions and Friends of the class in which it is declared, and by the member functions and Friends of the derived classes of this class.
3. If a member is public, its name can be used by any function.

Public protected private)
The access descriptor of the base class controls the access to the base class members, as well as the pointer and reference conversion from the derived class type to the base class type. Consider deriving Class D from base class B
1. If B is a private base class, its public and protected members can only be accessed by member functions and friends of D.
Only members and friends of D can convert D * to B *
2. If B is a protected base class, its public and protected members can only be accessed by member functions and friends of D, as well as member functions and Friends of the class derived from D. Only the members and supporting elements of D and the members and friendly elements of the class derived from D can convert D * to B *
3. If B is a public base class, its public member can be used by any function. In addition, its protected members can be accessed by member functions and friends of D, as well as member functions and friends of classes derived from D. Any function can convert D * to B *

 

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.