I firmly believe that you need to strictly separate classes based on value and classes based on OO (due to the lack of a better term).
A value-based class should not have shared databases and should usually support copy semantics (unless specifically designed to disable copying). Objects of such classes have no identities except their meanings. They are interchangeable with their copies.
OO-based classes should have virtual destructors and should never publicly receive copies. Objects of such classes should only be copied using the virtual clone method. Such objects have identities separated from their meanings.
There should not be a class with a public base in which there is no virtual destructor or a public copy / move ctor or a public copy / move assignment operator (in the database).
If you keep this separation, you will not have any accidents with the splitting of objects or their removal using a non-polymorphic base pointer.
Unfortunately, there are no tools (which I know) that help maintain this separation. Therefore, you need to exercise due diligence in inheritance. It is very simple. Does virtual dtor and inaccessible / remote copy ctor and copy destination? You can inherit in public. Not? Avoid potential disturbances, use composition or personal inheritance.
A good class intended for inheritance will be protected by its copy elements to facilitate cloning in descendant classes.
Unfortunately, with third-party classes, you have no choice, since authors usually leave public copying participants, so the risk of fragmentation of objects remains. But you will not have the risk of incorrect deletion using the base pointer.
TL; DR no tools, just for the due diligence of the programmer.
nm
source share