Reputation: 159
I'd like to use the C++11 override
specifier and noticed that it can be used together with virtual
. Does this make a difference? Consider the following classes:
class Base
{
virtual void fct() = 0;
};
class Derived1 : public Base
{
void fct() override {}
};
class Derived2 : public Base
{
virtual void fct() override {}
};
Is there a technical difference between Derived1
and Derived2
?
Upvotes: 2
Views: 232
Reputation: 385194
override
is always used together with virtual
. It is used to mandate that your virtual function overrides a virtual function in the base class.
An older rule means that, if it does override a virtual function in the base class, it's virtual automatically so you can skip writing the virtual
out in your code. But "conceptually" the virtual
is there already anyway.
So, writing virtual
there will make no difference at all. Since you wrote override
, the function must override a base class function (and, by extension, it must be virtual), otherwise your code won't compile.
Upvotes: 4