Explicit overrides and final C ++ 0x

According to Wikipedia , in this example:

struct Base {
    virtual void some_func(float);
};

struct Derived : Base {
    virtual void some_func(float) override;
};

I thought that is overridenot a C ++ keyword, so what does that mean? We can achieve the same without this keyword, so why would anyone need this?

There is also a keyword finalthat does not yet work on VS2010:

struct Base1 final { };

struct Derived1 : Base1 { }; // ill-formed because the class Base1 
                             // has been marked final
+5
source share
1 answer

In C ++ 11, overridethey finalare "identifiers with a special meaning." They are not keywords and acquire special meaning if they are used in a specific context (when declaring virtual functions).

, , (, , ).

, :

++ 11 10.3 4 f B virt-specifier final D, B, D:: f B:: f, . [:

struct B {
virtual void f() const final;
};
struct D : B {
void f() const; // error: D::f attempts to override final B::f
};

-end ]

5 virt override - , . [:

struct B {
virtual void f(int);
};
struct D : B {
void f(long) override; // error: wrong signature overriding B::f
void f(int) override; // OK
};

-end ]

+16

All Articles