C + + basic syntax: Common inheritance _c language

Source: Internet
Author: User

1. First of all, say the member function of the class or the 3 properties of the member variable:
public :
for objects and member functions are visible, that is, you can reference the
protected: for member functions that are visible, but invisible to objects, this declaration is mainly used in inheritance, which is discussed below
Private: is visible for member functions, invisible to objects

2, and then look at the way of inheritance:

Base class member keywords             derived class inheritance methods          derived class member access permissions for base classes
public                     public                 is equivalent to using the Public keyword
                           protected              is equivalent to using the procted keyword
                            private                is equivalent to using the Private keyword

protected                 protected             is equivalent to using the procted keyword
                            protected              is equivalent to using the procted keyword
                           private                is equivalent to using the Private keyword

Private public is equivalent to using the Private keyword
Protected equivalent to using the Private keyword
Private is equivalent to using the Private keyword


There are a few to note: the private members of the base class are not only invisible to the object, but also invisible to the derived class, and can only be accessed by a base class member or friend; the procted member is actually private to the object, except when it is inherited and private. Derived class members can access procted members of the base class; protected and private inheritance are rarely used in actual programming, and are mainly used in theoretical analysis.

PS: The object in this case is actually a variable declared by the class, the class defined inside the class is a private member of the class that can access it, and the variables defined within the class can also access the private members of the 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.