1
votes

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?

1
It seem you have no overload of new/delete in your base classuser2249683
maybe take a look at this SO post stackoverflow.com/questions/461203/…jon_shep

1 Answers

2
votes

You want to just call the destructor, something like:

myObjPtr->~MyClass()