final (C++)
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]
References
- 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
- 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.
See also
- final (Java)
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.