Quick Q: Is the 'override' keyword just a check for a overriden virtual method?

Quick A: Yes.

Recently on SO:

Is the 'override' keyword just a check for a overriden virtual method?

That's indeed the idea. The point is that you are explicit about what you mean, so that an otherwise silent error can be diagnosed:

struct Base
{
    virtual int foo() const;
};

struct Derived : Base
{
    virtual int foo()   // whoops!
    {
       // ...
    }
};

The above code compiles, but is not what you may have meant (note the missing const). If you said instead, virtual int foo() override, then you would get a compiler error that your function is not in fact overriding anything.

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.