Show: Object Pascal C++
Display Preferences

final (C++)

From Appmethod Topics
Jump to: navigation, search

Go Up to Keywords, Alphabetical Listing Index


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.

See Also

Personal tools
In other languages