Original Post
Well, I've looked all over Google and Gamedev's search page and I still havent found a way to call a class constructor.
I'm making amemory manager and I have it call new for an element, and when it's done it calls the destructor for that class. So, then I have the memory manager give out that memory the next time it needs a new class object. All is fine, but I cant call the class constructor.
I'll give some examples of what I'm talking about.
template< typename T >
class MmoryManager
{
T* New()
{
// Check to see if there is some "free" memory
if( bFreeMemory )
{
// This is what I can't do
// pData is a pointer to the "free" deconstructed object
pData->T(); // or pData->T::T();
}
else
{
return new T; // also keep track of this creation, but thats internal stuff
}
}
void Delete( T *ppDel )
{
ppDel->~T(); // or ppDel->T::~T();
// Some internal tracking of the memory for later use
}
}
I have tried making a local copy of T and memcpy the data into the "free" object, but something seems to be going wrong with my code, and I can't figure out what that is.
So, the main question: Is there a way to call the constructor for a class, or a alt for what I'm trying to do?
[edited by - newfound ajarn on March 8, 2004 7:53:19 PM]