9 ms·
I'm wondering why the "final" keyword is not mentioned in the article.
by 2716057 2y ago
I'm wondering why the "final" keyword is not mentioned in the article.
- repelsteeltje 2y agoWhat does "final" mean in C++? Is that new? Maybe you're confusing with java?
- canucker2016 2y agoC++11 adds support for specifying "final" on derived virtual functions to prevent further overriding of the function by any derived classes of the current "final" class.
- 1letterunixname 2y agoYep. Imported more-or-less from Java OOP.
- sudosysgen 2y agohttps://en.cppreference.com/w/cpp/language/final https://en.cppreference.com/w/cpp/language/final Final in C++ indicates that the function/class can no longer be overridden in further child classes. This enables devirtualization as the compiler can then know the function pointer will not change, if it can infer the type at compile time.
- epcoa 2y ago> Is that new? No. In fact in a few short months post C++11 will have overtaken pre-C++11 as the majority of the 26 year history of standardized C++ (and similar to prior standards, compilers for the fortunate implemented much of the behavior prior to the official publication).
- MichaelMoser123 2y ago> post C++11 will have overtaken pre-C++11 as the majority of the 26 year history of standardized C++ that's because they switched to a different 'release cycle' for C++ standards, also now they have minor releases like C++14.
- cout 2y agoThis is a good point. Using final and a static cast to the derived type should eliminate the indirect call.