template <class T>
class Allocator3D
{
....
// Returns NULL on failure
T *Alloc()
{
if (!FreeList)
if (!CreateNewChunk(SizeIncrement))
return NULL;
T *ret = FreeList;
FreeList = Next(FreeList);
ret->T::T(); // compiler gives error about class not having a T() function
return ret;
}
....
};
Explicitly calling a constructor
How can I explicitly call the constructor for a class?
You should be using placement new, which will not actually allocate the object, just construct one at the address you give.
Edit: One restriction I didn't know of is that the memory you construct it in has to be allocated on the heap.
Edit: One restriction I didn't know of is that the memory you construct it in has to be allocated on the heap.
Quote:Original post by MrEvil
You should be using placement new, which will not actually allocate the object, just construct one at the address you give.
Ohhhh, I didn't know you could do that...[smile]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement