I have an algorithm that needs to be executed with many implementations of a parent class named "Stack" (i.e. "LinkedStack", "ArrayStack", etc). I figured out that if I write this algorithm into a function and provide some sort of generic typing/template function magic, the problem would be solved.
But I didn't find any means to do so.
I've searched and tried many syntaxes but maybe it's just not possible?
template<class T: Stack> // Imaginary synthax to tell "T is a Stack"
void doTaskWithSpecificImplementation()
{
// Eventually somewhere in the function:
T stack = new T();
}
void main() {
doTaskWithSpecificImplementation<LinkedStack>();
}
I expect this code to provide a short and easy way to call a function while prescribing the use of specific virtual class implementation.