So since I didn't have the destructor, I decided to wrap the destruction in a static template function:
Code:
typedef uint8* (*DtorType)(uint8*);
template <class T> uint8* Dtor(uint8* pToDelete)
{
T* pObj = (T*)(pToDelete - sizeof(T));
pObj->~T();
return pObj;
}
and here is the templated allocation in the mempool. mpCurrent is the current pointer (uint8*) in the pool.
Code:
template <class T> void* Allocate()
{
if ((mpCurrent + sizeof(T) + sizeof(DtorType)) > (mpMemory + mSize))
{
return NULL;
}
else
{
uint8* pRet = mpCurrent;
mpCurrent += sizeof(T);
//this line is the problem
*mpCurrent = &Dtor<T>;
mpCurrent += sizeof(DtorType);
return pRet;
}
}
This compiles on Apple G++ 4.0.1.
But if I try to use the new operator, I get an error:
cannot resolve overloaded function 'Dtor' based on conversion to type 'unsigned char'
And it doesn't even compile in Visual C++:
cannot convert from 'uint8 *(__cdecl *)(uint8 *)' to 'uint8'
I tried replacing uint8* with void*, but I can't perform arithmetic operations on a void* type.