lundi 2 octobre 2017

Why use of "override" is not allowed in method definition?

Override is quite informative keyword. However, one can use it in class declaration only. Is there any reason to forbid its use in definitions? Example:

class Base
{
public:
    virtual void Method() = 0;
};

class Child : public Base
{
public:
    void Method() override;
};


// source.cpp

void Child::Method() override        // oops
{
    ...
}

Aucun commentaire:

Enregistrer un commentaire