You could do this:
struct KalmanModelCV {
typedef KalmanCV filter_t;
typedef StateCV state_t;
};
class track {
public:
track() {
filter_ = NULL;
state_ = NULL;
}
typedef<typename Model>
void ChangeModel() {
delete filter_;
delete state_;
filter_ = new typename Model::filter_t();
state_ = new typename Model::state_t();
}
private:
KalmanStrategy* filter_;
StateBase* state_;
};
track t;
t.ChangeModel<KalmanModelCV>();
However, if every filter requires its own specific state type, it would be better to move the creation of states to the filter class. For example:
class KalmanStrategy {
public:
virtual void Prediction(StateBase* state) = 0;
virtual void Correction(StateBase* state) = 0;
virtual StateBase* CreateState() = 0;
virtual ~KalmanStrategy(){}
protected:
KalmanStrategy() {}
};
class KalmanCV : public KalmanStrategy {
public:
KalmanCV(){}
void Prediction(StateBase* state) {...}
void Correction(StateBase* state) {...}
StateBase* CreateState() { return new StateCV(); } // KalmanCV only works with StateCV!
};
class track {
public:
track() {
filter_ = NULL;
state_ = NULL;
}
void ChangeModel(KalmanStrategy* strat) {
delete filter_;
delete state_;
filter_ = strat;
state_ = strat->CreateState();
}
private:
KalmanStrategy* filter_;
StateBase* state_;
};