I've got a base class with a pure virtual function:
class Allocator
{
public:
template< class T >
virtual T* allocate(T type) = 0;
};
with a derived class with a templated function which the design intent was to override this virtual function:
class StackAllocator: public Allocator
{
public:
StackAllocator(size_t size, void* stackStart = nullptr);
template< class T>
T* allocate(T Type);
};
My design intent was to have allocate override the allocate in Allocator. But obviously after reading up on this, i have found the code above will not work.
I found alot of solutions that involve making the class itself a template, but in this situation i can't do this as the StackAllocator itself needs to be type-agnostic at compile. And only the function should deal with the varying types.
I found a work-around that involved making an 'allocation' class that was used on a per allocation basis that dealt with the allocation itself, but this seemed wasteful and not very clear in its application so now i'm stuck with simply getting rid of the virtual function and using just the derived class templated function.
Any ideas how i could do this? or ideas for how to rework my design? (bear in mind that i will be eventually making many more derived allocators so the base is necessary.)
Thanks!