Skip to content

override Specifier (C++11)

In a Nutshell

Appending override to a virtual function declaration instructs the compiler to verify that the function successfully overrides a base class virtual function. Signature mismatches or attempts to override non-virtual functions will result in a compilation error.

None (This is a language-level keyword feature)

Core API Quick Reference

OperationSignatureDescription
Function declarationvoid foo() override;Used in declarations to ensure overriding of a base class virtual function
Function definition (in-class)void foo() override { }Used when defining the function inside the class
Pure virtual function overridevoid foo() override = 0;override appears before = 0
Combined with finalvoid foo() override final;Can be combined with final in any order
Destructor override~Derived() override;Can be used to check overriding of virtual destructors

Minimal Example

cpp
struct Base {
    virtual void func() { /* ... */ }
    virtual void only_in_base() { /* ... */ }
};

struct Derived : Base {
    // Correctly overrides Base::func
    void func() override { /* ... */ }

    // Error: 'only_in_base' is not virtual in Base
    // void only_in_base() override;

    // Error: signature mismatch (const qualifier)
    // void func() const override;
};

Embedded Applicability: High

  • Zero runtime overhead; performs static checks exclusively at compile time.
  • Embedded code often features multi-layer Hardware Abstraction Layers (HALs); override effectively prevents silent errors caused by changes to base class interfaces.
  • Does not impact code size or execution speed, making it suitable for resource-constrained environments.

Compiler Support

GCCClangMSVC
4.73.02012

See Also


Part of the content references cppreference.com, licensed under CC-BY-SA 4.0

v0.7.0-9-g940ec1b · 940ec1b · 2026-07-05