Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the relationship between inheritance mode and access qualifier in C++

Shulou Source: shulou.com Published: 2022-06-03 14:43:05 11月14日 Update

This article is to share with you about the relationship between inheritance and access qualifiers in C++. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The relationship between inheritance mode and access qualifier

There are three ways of inheritance:

Public inheritance

Private inheritance

Protect inheritance

Relationship: if the member function of the base class is private, the derived class is invisible to the private members of the base class, and the other criteria are limited to the final access if the selection scope is small.

Protect member qualifier: some base class members do not want to be directly accessed by the object of the base class, but can only be accessed in a derived class, which is defined as a protected member. The protection member qualifier appears because of inheritance.

Understand concealment

Hiding means that the function of the derived class masks the base class function with the same name. The rules are as follows:

If the function of the derived class has the same name as the function of the base class, but the arguments are different, the function of the base class will be hidden with or without the virtual keyword.

If the function of the derived class has the same name as the function of the base class and the parameters are the same, but the function of the base class does not have the virtual keyword, the function of the base class is hidden.

Default member function of a derived class

If the six default member functions are not defined in the derived class, the compiler will default to the six member functions.

Constructor function

Copy constructor

Destructor function

Assignment operator overload

Address operator overload

Const modified address operator overload

# includeusing namespace std;class person {public: person (const char* name): _ name (name) {cout

Tags: Function member mode protection operator diamond private clocked relay same key keyword content address data more article different good practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Linux Huawei Microsoft Shulou Technology