C + + Inheritance

Source: Internet
Author: User

Public,protected,private Access Summary in C + +
First: The access scope of the Private,public,protected method. (Under public inheritance)
Private: can only be accessed by a function in the class, its friend function, and cannot be accessed by any other object of the class.
Protected: can be accessed by functions in the class, functions of subclasses, and their friend functions, but cannot be accessed by objects of that class
Public: can be accessed by functions in the class, by functions of subclasses, by their friend functions, or by objects of that class
Note: The friend function consists of two kinds: global function set as friend, set as member function in friend class

Second: Post-Inheritance Method property changes for classes:
With private inheritance, all methods of the parent class become private in subclasses;
With protected inheritance, the protected and public methods of the parent class change to Protected,private method in the subclass;
Using public inheritance, the method attribute in the parent class does not change;

Protected inheritance and private inheritance can reduce access rights

C + + Inheritance

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.