I have a parent_class which has a lot of child_class(es). The parent_class defines a function
void generate() = 0;
which is defined by all the child classes.
I have another class called "Generator" which has a pointer-to-parent_class constructor. The "Generator" class makes use of the generate() function.
Here's the problem. The child_classes take different arguments (a single object as argument) for generate();
So maybe we could template void generate(); like so:
virtual void generate(T) { }
full declaration:
1 2 3 4 5 6 7 8 9 10
|
template <typename T>
class parent_class {
public:
virtual ~parent_class() { }
parent_class() { }
virtual void generate(T) { }
};
|
Generator class becomes:
1 2 3 4
|
template <typename T>
class Generator {
Generator(parent_class<T>* obj) { }
};
|
But I don't want to write
parent_class<T>
because then Generator would then have to be instantiated with a type as well, which I want to avoid. For convenience sake.
(It's guaranteed that the Generator class will know what to call the generator() with.)
The only other way I could think of was to manually write all overloads of generate(), but that's tedious when you are expecting to add more child classes.