◐ Shell
clean mode source ↗

final specifier — cppreference.com

De cppreference.com

<metanoindex/>

Indique qu'une fonction virtuelle ne peut pas être substituée dans une classe dérivée ou qu'une classe ne peut pas être héritée

Original:

Specifies that a fonction virtuelle can not be overridden in a derived class or that a class cannot be inherited

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Syntaxe

function_declaration final ;
class class_name final base_classes

Explication

Lorsqu'il est utilisé dans une déclaration de fonction virtuelle, final spécifie que la fonction ne peut pas être remplacée par des classes dérivées .

Original:

When used in a virtual function declaration, final specifies that the function may not be overridden by derived classes.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

final est un identifiant avec une signification particulière lorsqu'il est utilisé dans une déclaration de fonction membre ou chef de classe. Dans d'autres contextes ne sont pas réservés et peuvent être utilisés pour nommer des objets et des fonctions .

Original:

final is an identifier with a special meaning when used in a member function declaration or class head. In other contexts it is not reserved and may be used to name objects and functions.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Exemple

struct A
{
    virtual void foo() final;
};

struct B final : A
{
    void foo(); // Error: foo cannot be overridden as it's final in A
};

struct C : B // Error: B is final
{
};

Voir aussi