An example Analysis of the Constructor inherited by Category 11
The main content of this article is to explain "an example analysis of the constructor inherited by Category 11". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn the example analysis of the constructor inherited by Category 11.
Suppose we have the following CRect class:
Since today's story is about constructors, other features of the CRect class are omitted. There are four constructors in this class, and you can use them as follows:
The little trouble of inheritance
For some reason, we need to inherit this class to get a new class, such as CFillRect, but we also want to construct the instance in the same way as CRect, that is, we want to use the new class like this:
Before Category 11, we can only define these four constructors again in CFillRect, and then call the corresponding functions of the base class respectively. The code is roughly as follows:
To be honest, it's a little stupid.
Inherited constructor
In the new C++ standard, derived classes only need a declaration statement to achieve the above functions:
Isn't that better?
At this point, I believe that you have a deeper understanding of the "example analysis of the constructor inherited by Category 11". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!