Namespaces
Variants
Views
Actions

override specifier

From cppreference.com
 
 
C++ language
General topics
Preprocessor
Comments
Keywords
ASCII chart
Escape sequences
History of C++
Flow control
Conditional execution statements
Iteration statements
Jump statements
Functions
function declaration
lambda function declaration
function template
inline specifier
exception specifications (deprecated)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
decltype specifier (C++11)
Specifiers
cv specifiers
storage duration specifiers
constexpr specifier (C++11)
auto specifier (C++11)
alignas specifier (C++11)
Literals
Expressions
alternative representations
Utilities
Types
typedef declaration
type alias declaration (C++11)
attributes (C++11)
Casts
implicit conversions
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-style and functional cast
Memory allocation
Classes
Class-specific function properties
virtual function
override specifier (C++11)
final specifier (C++11)
Special member functions
Templates
class template
function template
template specialization
parameter packs (C++11)
Miscellaneous
Inline assembly
 

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