Question

So I've written my own memory management class.

Essentially it allocates a big block of memory via malloc, then upon request it hands over the memory to the requester in the program (as you would expect.)

I've also implemented templated allocation and free functions, which explicitly calls the constructor and destructor based on the templatized class.

The problem, as you might already be realizing, is what about when I attempt to delete through a base pointer?

The templated function picks up the base class' type, and thus the base's virtual destructor is called, not the correct derived destructor.

There doesn't happen to be a placement delete or anything that would function like a regular "delete" command but not attempt to deallocate the memory?

Was it helpful?

Solution

You want to just call the destructor, something like:

myObjPtr->~MyClass()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top