Final_(C++)

final (C++)

final (C++)

Keyword in the C++ programming language


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

  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. 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. Brand, Sy (2020-03-02). "The Performance Benefits of Final Classes". C++ Team Blog. Retrieved 2024-04-23.
  5. TylerMSFT (2021-08-03). "final Specifier". learn.microsoft.com. Retrieved 2024-04-23.
  6. Stroustrup, Bjarne (2013-07-10). The C++ Programming Language. Addison-Wesley. ISBN 978-0-13-352285-3.

See also



Share this article:

This article uses material from the Wikipedia article Final_(C++), and is written by contributors. Text is available under a CC BY-SA 4.0 International License; additional terms may apply. Images, videos and audio are available under their respective licenses.