top | item 39782546

(no title)

2716057 | 1 year ago

I'm wondering why the "final" keyword is not mentioned in the article.

discuss

order

cout|1 year ago

This is a good point. Using final and a static cast to the derived type should eliminate the indirect call.

repelsteeltje|1 year ago

What does "final" mean in C++? Is that new? Maybe you're confusing with java?

epcoa|1 year 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).

canucker2016|1 year ago

C++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.

sudosysgen|1 year ago

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.