I’m trying to define an abstract interface class `AbstractSystemInterface`

for a dynamical systems problem. The dynamical system has an `n`

dimensional state vector and an ‘m’ dimensional input vector whose lengths are known(at compile time) by the developer who implements my interface. The developer in their derived class also implements functions on actually populating the state vector based on input from the user. From the users perspective they just need to instantiate the interface and be able to call the `getState`

and `setInput`

functions. My solution is to use a class template with virtual functions like this:

```
template<class StateVector, class InputVector>
class AbstractSystemInterface {
public:
virtual StateVector getState() = 0;
virtual void setInput(InputVector &u) = 0;
protected:
StateVector state;
InputVector input;
};
```

So a developer derived class would look like this:

```
class RealSystemInterface : public AbstractSystemInterface<Eigen::Matrix<double, 6, 1>, Eigen::Matrix<double, 3, 1>> {
public:
virtual Eigen::Matrix<double, 6, 1> getState() override {
return state;
};
virtual void setInput(Eigen::Matrix<double, 3, 1> &input) override {
/** potentially do some other computation here **/
state = applyToSytem(input);
};
private:
void applyToSystem(Eigen::Matrix<double, 3, 1> &input);
};
```

Now if I understand correctly, this doesn’t work as intended as the instantiated RealSytemInterface will be of a different type based on the input template parameters. It’s not obvious to me that this is a problem, but I suspect that I might want to be able to treat any RealSystemInterface as a single type `AbstractSystemInterface`

sometime in the future. What are the ways around this problem?

Source: Windows Questions C++