Is there any reason to specify a function as final
when the class is already final
? Or is that redundant?
class B
{
public:
virtual void f();
};
class D final : public B
{
public:
virtual void f() final; // Redundant final?
};
Would it be a good rule of thumb to say: Start with making the whole class final
, and only switch to making individual functions final
when you need to derive from the class and/or override specific functions?
It is definitely redundant because marking whole class as final
makes it impossible to derive from this class and therefore override anything.
9 Classes [class]
- If a class is marked with the class-virt-specifier final and it appears as a base-type-specifier in a base-clause (Clause 10), the program is ill-formed.
So compiler won't even bother to check whether class deriving from final
class actually tries to override anything or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With