In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article "C++ data structure inheritance concept and diamond inheritance and virtual inheritance and combination analysis" most people do not understand the knowledge points of the article, so Xiaobian summarized the following content for everyone, detailed content, clear steps, with a certain reference value, I hope you can read this article to gain something, let's take a look at this article "C++ data structure inheritance concept and diamond inheritance and virtual inheritance and combination analysis" article bar.
the concept of inheritance
Inheritance: Inheritance mechanism is the most important means of object-oriented programming to make code reusable. It allows programmers to extend and increase functions on the basis of maintaining the original class characteristics, thus generating new classes, called derived classes. Inheritance presents the hierarchy of object-oriented programming, representing the cognitive process from simple to complex. Previously, the reuse we touched was function reuse, and inheritance was reuse at the class design level.
Definition of Inheritance
Grammar:
Description: Derived classes inherit both member variables and member functions from the base class, but access qualifiers vary depending on how they are inherited.
There are three ways to inherit:
public inheritance
protected inheritance
private inheritance
Access qualifiers:
public access
protected access
private access
Changes in access to inherited base class members:
class member/inheritance method public inheritance protected inheritance private inheritance public member of base class public member of derived class protected member of derived class private member of base class protected member of derived class protected member of derived class private member of base class invisible in derived class
Summary:
The private members of the base class are invisible in derived classes, where invisible refers to private members of the base class or inherited into derived class objects, but syntactically restricts derived class objects from accessing them both inside and outside the class.
Access method of base class member in parent class =min (access qualifier of member in base class, inheritance method), public>protected>private.
Members of the base class that you don't want to have out-of-class access to are generally set to protecd members, not accessible outside the class, but accessible to derived classes.
Assignment conversion between base class and derived class objects
Derived class objects are assigned to objects, pointers, or references of the base class by "slicing" or "cutting." But base class objects cannot be assigned to derived class objects.
Example demonstration:
class Person{public: Person(const char* name = "") :_name(name) {} void Print() { cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.