When organizing inheritance structure and needing to make base class abstract, is there any reason to prefer a pure virtual destructor over protected constructor (or vice versa)? This question already exists here, but the accepted answer doesn't really answers it. The problem of
Base *ptr = new Derived();
delete ptr;
can be solved using both approaches:
- make dtor pure virtual and define body for it
- make dtor virtual and make ctor protected
As I understand, the only thing that will differ is the compiler error at trying to Base *ptr = new Base()
: Cannot instantiate abstract class
in first case vs. Cannot access protected member
in second case, with first being more accurate. Is this the question of style, or is there something I'm not aware of?
As a somewhat related question, will the same rules be applied to some class in inheritance chain that is not strictly a base one, but still should be abstract (i.e. Monster
inheriting from GameObject
cannot be created, but Orc
inheriting from Monster
can)?