It has been suggested that this article be merged into C++ classes. (Discuss) Proposed since April 2024. |
final
is a keyword in the C++ programming language.[1] It limits the ways in which a class can be subclassed. Subclasses of a class are prevented from overriding methods marked as final
by the parent class.[2][3] Final classes cannot be inherited.[3] This allows devirtualization, the removal of the use of vtables for method lookup, thus allowing the inlining of method calls on final classes.[4][5]
final
is not a reserved word in C++, and is instead defined as a contextual keyword, in order to not conflict with uses of the identifier 'final' in existing codebases.[6][7]
See also
editReferences
edit- ^ ISO International Standard ISO/IEC 14882:2020(E) – Programming Language C++.
- ^ Browning, J. Burton; Sutherland, Bruce (2020), Browning, J. Burton; Sutherland, Bruce (eds.), "Inheritance", C++20 Recipes: A Problem-Solution Approach, Berkeley, CA: Apress, pp. 205–207, doi:10.1007/978-1-4842-5713-5_6, ISBN 978-1-4842-5713-5, retrieved 2024-04-24
- ^ a b Lakos, John; Romeo, Vittorio; Khlebnikov, Rostislav; Meredith, Alisdair (2021-12-16). Embracing Modern C++ Safely. Addison-Wesley Professional. ISBN 978-0-13-738051-0.
- ^ "16BPP.net: Blog / The Performance Impact of C++'s 'final' Keyword". 16bpp.net. Retrieved 2024-04-23.
- ^ Brand, Sy (2020-03-02). "The Performance Benefits of Final Classes". C++ Team Blog. Retrieved 2024-04-23.
- ^ TylerMSFT (2021-08-03). "final Specifier". learn.microsoft.com. Retrieved 2024-04-23.
- ^ Stroustrup, Bjarne (2013-07-10). The C++ Programming Language. Addison-Wesley. ISBN 978-0-13-352285-3.
This article needs additional or more specific categories. (April 2024) |