I have a base class with a few clean virtual methods like
class GenericFunction { public: GenericFunction() { }; virtual void Iterate(short *ps, unsigned cs) = 0; virtual void Iterate(float *ps, unsigned cs) = 0; }
Then I have a bunch of derived classes that implement certain functions, and I want to call the Iterate() method on the set of these functions, providing each of them with a block of data samples. I only know the data type the moment I call Iterate() .
The Iterate() methods Iterate() almost the same for many functions, so I would like to use a template. I cannot use the template in the base class because virtual templates are not allowed. To get the compiler to generate the correct methods from the template, I found that I need to use an indirect call to the template as follows:
class SpecificFunction : GenericFunction { public: SpecificFunction() : GenericFunction() { }; template<class T> void IterateT(T *ps, unsigned cs) {
I donβt want to do the whole class for the SpecificFunction template, because there are many other methods, and all this code does not depend on the type of samples used. I do not want all this code to be replicated when it was created from a template, because it works in the embedded processor and in the code space.
It seems confusing and ineffective. Is there a better way to do this?
source share