When I read a book on C ++ over the past two days, I feel a little unfamiliar with an inherited knowledge point. Maybe I have never been in touch before, maybe I have never been in touch for too long, but I forget it now. It should be noted down to make a memo. By the way, let's look at the concept of inheritance.
That is the access statement in C ++.
As we all know, C ++ has three inheritance Methods: Public inheritance, protection inheritance, and private inheritance. Public inheritance: the public and protected members of the base class do not change in the nature of the derived class. Protection inheritance: the public and protected members of the base class become protected members in the derived class. The protection member is designed for the inheritance mechanism so that it is visible in the derived class and invisible outside the class. Private inheritance: all the members of the base class are converted into private members in the derived class.
The problem is that when I use some inheritance method, I want to change a member of the base class into another access method. How can I implement it? Therefore, the access adjustment mechanism is used.
Class
{
Publice:
Int get_data (int x, int y );
Int data;
}
Class B: Private
{
Publice:
A: get_data;
Int get_s () {return s ;};
Int set_s () {S = x * Y ;};
PRIVATE:
Int S;
};
Obviously, if a: get_data is not added to publice of B, get_data will become a private member in B. The access declaration can convert it to public.
Note that:
The object declared in the access declaration cannot be of any type or contain parameters or return types.
Private Members of the base class cannot be used for access declaration.
The accessibility of base class members cannot be reduced or improved. For example, the Public Members of the base class cannot be declared as protection, and the protection cannot be declared as public.
The access Declaration for the overload function name will adjust the access domains of all functions with the same name in the base class. However, functions with different access domains in the base class cannot be used for access declaration, a function of the same name as a base class does not support access declaration.
It seems that there have been a lot of errors!