C ++ the override and final

1, final virtual functions may not be so for rewritable

struct B2
{
    virtual void f() final {} // final 函数
};

struct D2 : B2
{
    virtual void f() {}
};

As the code is not being compiled

2、override

1. In the case of more functions may remind the reader of a certain function overrides the base class virtual function (virtual function indicates that this is inherited from the base class, the derived class is not their own definition);

2. Force compiler checks whether the override a function in the base class virtual function, then if there is no error.

Guess you like

Origin www.cnblogs.com/judes/p/11595365.html