Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of the Constructor inherited by Category 11

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report