In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 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 how to use the override specifier of Clover 11. Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the override specifier of Clippers 11.
Polymorphisms and imaginary functions
Polymorphism is not only one of the important characteristics of C++, but also difficult for beginners to understand. Let's start with a simple example:
The code is simple. To describe the main points of polymorphism from definition to function in the above code, according to the author's own words, it should not be any easier, starting with the main function:
Pointer to the base class
An object that points to a derived class
The derived class overrides the virtual function defined in the base class
These three points are necessary and indispensable.
There are other interesting things about the above code, which doesn't affect the result, but it's better to know about it. When you redefine (override) a virtual function in the base class in a derived class:
The virtual keyword is not a must
It is not necessary to declare the function as public
Override a failed situation
The coverage of virtual functions requires that the signatures of the two functions must be the same. For example, the following code:
Polymorphism cannot be implemented because the signature of sub2::f1 is not consistent with that of base::f1.
You may think this mistake is too obvious to happen at all. That's because the member function in this example is too simple. In the actual development, with the expansion of the development scale, the inheritance relationship of the class will become deeper and deeper, and the parameters of the member function will become more and more. It is often encountered that the signature of the member function defined in the derived class is inconsistent with the signature of the overlay object, which leads to the overwrite failure.
And fatally, this kind of error does not produce compilation errors and is not easy to find.
Override specifier
To solve this problem, override specifier is used when declaring and defining override functions in derived classes.
Because of the clear intention of the function, a compilation error occurs when the compiler cannot find a virtual function with the same signature in the base class.
At this point, I believe you have a deeper understanding of "how to use the override specifier of Clippers 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.
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.