final (C++)
Go Up to Keywords, Alphabetical Listing Index
Note: This feature is available only for the classic bcc32 compiler, not for the modern Clang-enhanced compiler.
Syntax
FUNCTION NAME [[final]]
Description
The final attribute prevents a class from being further inherited or prevents a function from being overridden. You can add the final attribute to a class definition or to a virtual member function declaration inside a class definition.
A class with the final attribute is not allowed to be a base class for another class. A virtual function with the final attribute cannot be overridden in a derived class.
If a virtual member function f in some class B is marked final and in a class D derived from B, a function D::f overrides B::f, the program is ill-formed (the compiler does not issue a message).
Example
struct B
{
virtual void f [[ final ]] ();
};
struct D : B
{
void f(); // ill-formed
};
Portability
POSIX | Win32 | Win64 | ANSI C | ANSI C++ | |
---|---|---|---|---|---|
deprecated |
+ |
Note: The final attribute is not supported by Clang-enhanced C++ compilers.