Cppcoreguidelines: Override on derived class destructors

Created on 14 Jun 2019  路  3Comments  路  Source: isocpp/CppCoreGuidelines

If a base class destructor is declared virtual, one should avoid declaring derived class destructors virtual or override.

Why is this?

Using override on a derived class destructor provides protection against the base class destructor accidentally being made non-virtual, thus introducing subtle, hard to detect and hard to diagnose memory leaks. @

Most helpful comment

What annoys me the most is that it is an absolutely needless exception to an otherwise straightforward rule: "Virtual functions should be marked with exactly one of virtual, override or final".

C++ guidelines already have far too many exceptions (most of the time for good reason) - we don't have to artificially complicate them further.

All 3 comments

Okay, so based on that thread, the only real reason is that it's unusual because destructors aren't really inherited - an implementation detail. As far as I can tell, doing so has absolutely zero practical negative implications.. and a very useful positive impact. So my question still stands, really.

What annoys me the most is that it is an absolutely needless exception to an otherwise straightforward rule: "Virtual functions should be marked with exactly one of virtual, override or final".

C++ guidelines already have far too many exceptions (most of the time for good reason) - we don't have to artificially complicate them further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

beinhaerter picture beinhaerter  路  5Comments

RedDwarf69 picture RedDwarf69  路  3Comments

imre-palik picture imre-palik  路  6Comments

rmasp98 picture rmasp98  路  7Comments

qalpaq picture qalpaq  路  5Comments