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?

有帮助吗?

解决方案

You want to just call the destructor, something like:

myObjPtr->~MyClass()

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top