override specifier

From Cppreference

Jump to: navigation, search

Specifies that a virtual function overrides another virtual function.

Contents

[edit] Syntax

function_declaration override ;

[edit] Explanation

In a method declaration, override specifies that the function must be overriding a base class method.

override is an identifier with a special meaning when used after function declaration, otherwise it's not reserved.

[edit] Example

struct A
{
    virtual void foo();
    void bar();
};
 
struct B : A
{
    void foo() const override; // Error: Has a different signature from A::foo
    void foo() override; // OK: base class contains a virtual function with the same signature
    void bar() override; // Error: B::bar doesn't override because A::bar is not virtual
};

[edit] See also