I don't understand why I am getting compiler errors when trying to compile this:
void* MemoryManagedObject::operator new(size_t size, bool UseMemPool)
{
Engine* engine = Engine::GetEngine();
void* alloc;
alloc = engine->GetMemoryManager()->Allocate(size, UseMemPool);
if (alloc && UseMemPool)
mAllocatedWithMemPool = true;
return alloc;
}
It says "invalid use of member MemoryManagedObject::mAllocatedWithMemPool in static member function".
Basically, I have a flag that states whether I used my memory pool or just malloc() when allocating the class instance, and I want to set it when I override 'new'.
I guess the 'new' method must return before you can use the class instance? Is there any way around this?
EDIT: Just curious, ss this code a valid solution as well?
void* MemoryManagedObject::operator new(size_t size, bool UseMemPool)
{
Engine* engine = Engine::GetEngine();
MemoryManagedObject* alloc;
alloc = (MemoryManagedObject*)engine->GetMemoryManager()->Allocate(size, UseMemPool);
if (alloc && UseMemPool)
alloc->mAllocatedWithMemPool = true;
return alloc;
}