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.

Project Activity

See All Activity >

Follow MethodChainer

MethodChainer Web Site

Other Useful Business Software
Forever Free Full-Stack Observability | Grafana Cloud Icon
Forever Free Full-Stack Observability | Grafana Cloud

Our generous forever free tier includes the full platform, including the AI Assistant, for 3 users with 10k metrics, 50GB logs, and 50GB traces.

Built on open standards like Prometheus and OpenTelemetry, Grafana Cloud includes Kubernetes Monitoring, Application Observability, Incident Response, plus the AI-powered Grafana Assistant. Get started with our generous free tier today.
Create free account
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of MethodChainer!

Additional Project Details

Registered

2014-12-29