final (C++)

From Wikipedia, the free encyclopedia
(Redirected from Draft: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[edit]

  1. ^ ISO International Standard ISO/IEC 14882:2020(E) – Programming Language C++.
  2. ^ 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
  3. ^ 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.
  4. ^ "16BPP.net: Blog / The Performance Impact of C++'s `final` Keyword". 16bpp.net. Retrieved 2024-04-23.
  5. ^ Brand, Sy (2020-03-02). "The Performance Benefits of Final Classes". C++ Team Blog. Retrieved 2024-04-23.
  6. ^ TylerMSFT (2021-08-03). "final Specifier". learn.microsoft.com. Retrieved 2024-04-23.
  7. ^ Stroustrup, Bjarne (2013-07-10). The C++ Programming Language. Addison-Wesley. ISBN 978-0-13-352285-3.

See also[edit]