Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The use of the final specifier in Clippers 11

Shulou Source: shulou.com Published: 2022-06-02 04:30:03 09月10日 Update

The main content of this article is to explain the use of the final specifier in Clover 11. Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn the use of the final specifier in Clippers 11.

When we declare / define a virtual function, the derived class can choose to override the virtual function or not. At this point, C++ also provides the necessary methods to require derived classes to override certain methods, which can also be seen as a way to program in the future.

Pure virtual function

This is not a new technology, and the function is very simple: once a base class declares a pure virtual function, its derived class must override that function when instantiated.

In this example, the sub::f1 () method is commented out, so a compilation error occurs on line 27.

Final specifier

Generally speaking, if there is a required method of coverage, there should be a means to prohibit coverage. But for some reason, this feature was not introduced until Category 11. How to use it is also simple: just add the final specifier after the function declaration.

The code is basically the same, except that the base::f1 () declaration is followed by a final specifier. At this point, if the sub::f1 () method is defined, a compilation error like the one shown above will be generated.

At this point, I believe you have a deeper understanding of the use of the final specifier in 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!

Tags: Method specifier function content function time error learning compilation selection practical deeper necessary generally speaking figure above code usage interest just example Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information macOS Huawei Microsoft