I've started learning C++ templates, so I wrote something like the code below. I used a template to make a "generic inheritance". It works, but I haven't found many similar examples, which leads me to believe that this is not a recommendable implementation.
edited
Sorry about the simple example, I will to try to improve this, so I'm writing a linear/nonlinear(extended) Kalman filter, and I'm using templates to define whether the system is linear or nonlinear.
// https://godbolt.org/z/WhdonxY9x
#include <iostream>
#include <vector>
class Linear
{
public:
Linear(){};
void init(){};
void time_update(){};
};
class Nonlinear : public Linear
{
public:
Nonlinear(){};
void loadEq(){};
void applyLinearization(){};
};
template <class Model>
class Filter : public Model
{
public:
Filter(){};
void measurement_update(){};
};
int main(int argc, char **argv)
{
std::vector<double> data{0.3, 0.2, 0.3};
// for nonlinear system
Filter<Nonlinear> nFilter;
for (auto x : data)
{
nFilter.applyLinearization();
nFilter.time_update();
nFilter.measurement_update();
}
// for linear system
Filter<Linear> lFilter;
for (auto x : data)
{
lFilter.time_update();
lFilter.measurement_update();
}
return 0;
}