When learning the inheritance of C ++, we are often confused by access attributes, and it is not easy to remember. It is more difficult for beginners to understand. So how can we remember it and it is not easy to forget it? That is to remember it on the basis of understanding. Most books often describe this piece of text in three paragraphs, and you will be confused if you don't get dizzy, it's okay to extract it into your own language.
Let's take a look at the inheritance form of the class:
Class derived class name: [access attribute] Base class Name
{
}
There are three access attributes: public, protected, and private. This makes it easier to remember. During inheritance:
1. No matter which form (public, protected, or private) is used, private Members in the base class cannot be inherited. If you have to use private members of the base class in the derived class, there are two ways to do this: use attributes, and use friend functions.
2. If the public form is used, all the other private members of the base class are inherited to the derived class as they are; that is, the base class is public, it is public in the derived class, protected in the base class, and protected in the derived class.
3. If the form of protected is used, all other statements of the base class except the private member are inherited to the derived class in the form of protected.
This seems a little organized and easy to remember. Therefore, understanding is very important in the process of learning. It is much easier to remember to interpret the language in the book into your own language.