I’m facing the following conundrum in C++ for which I can’t seem to find a solution. I have an abstract class Model
at the top of my inheritance hierarchy which I need to contain a member variable representing the model parameters. It implements a whole bunch of boilerplate logic and is used for polymorphism. The type of this variable depends on the most derived classes implementing concrete models, e.g. HullWhite
needs to inherit a HullWhiteParams
member from Model
.
There are multiple layers of inheritance in between these two. If there was only one layer, this could be solved by CRTP. I also cannot have the intermediate classes be templated, as I require pointers to them for polymorphism. Is there any way of achieving this? I’m essentially looking for a CRTP-like pattern that passes leaf class information all the way back to the top of the hierarchy.