I currently have a Base Class Env, which is an interface, and I have several derived classes.
class Env
{
public:
//method in question
virtual std::tuple<Eigen::VectorXf,float,bool,std::string> step(const //what goes here?//)=0;
virtual ~Env(); //virtual destructor
};
An example derived class is as follows (header)
class MountainCar: public Env
{
public:
MountainCar();
std::tuple<VectorXf,float,bool,std::string> step(const int) override;
};
Now, the design is that all the environments must inherit from Env. However, I want to enforce all the environments to implement the step() method, which is why the step method in the base Env is a pure virtual.
However, each derived Env can take different argument types in the step method, and this should be a valid override. Example, mountain car defines it with an int argument.
Initially, I made the base class a template class with parameter U, and passed U to the step method. Then, the derived classes used to inherit from template instantiations, example MountainCar inherited from Env. However, the issue is that all the derived classes inherit from different instantiations of the base class, and I can no longer use a common base pointer for polymorphism.
How do I design this system with C++11 features?
Aucun commentaire:
Enregistrer un commentaire