C++ virtual function is a useful tool for a superclass to control in what timing the subclass's virtual method override is called.
However, the virtual function mechanism calls only one of the overrides, which is the one overridden by the 'leaf' class in the class hierarchy.
When there are three or more classes in the hierarchy chain, and if some or all of the virtual method overrides need to be executed, the typical way we do is to call its direct superclass's virtual method manually in the subclass like this:
Child::foo() {
// ...
Parent::foo().
// ...
}
Sometimes the superclass's method needs to be called before the subclass does stuff for it and sometimes vice versa.
This manual chaining of methods is error prone and here is the solution for it.
Downloads:
0 This Week