3 ms·
Why do protected virtual methods lead to an explosion?
by DeathArrow 1y ago
Why do protected virtual methods lead to an explosion?
- bheadmaster 1y agoProtected = subclasses can call them. Virtual = subclasses can override them. So basically, any subclass can call the method, and that method may be overridden in any other subclass.
- zelphirkalt 1y agoWhat is the issue with those overrides? They only affect that one path in the hierarchy of inheritance, no? Not a C++ user here, but I imagine it would be catastrophic, if an unrelated (not on path to root superclass) class could override a method and affect unrelated classes/objects.
- bheadmaster 1y ago> They only affect that one path in the hierarchy of inheritance, no? Not necessarily. If you create a diamond (or a spiderweb :) inheritence pattern, the amount of places the method can be called and overriden grows fast.