For a memory manager that I am writing in C++ as a proof of concept, in order to keep track of allocated objects I am allocating memory with malloc()
in a function, then returning the pointer to that memory and using the placement new operator. Then, to track when the object is deleted, I pass the pointer into another function to call free()
on the pointer.
However, since I am using free()
instead of delete
, the object's constructor is not automatically called like it usually is, so I have to call it myself. Also, since the memory manager is designed to work with any object, it is conceivable (and even likely) that at some point in it's lifetime it will have to free an object that potentially has multiple parent classes or is deep within an inheritance tree.
My initial solution to this would be to call the base objects destructor, which would call all of the child destructors (if this question is to be believed), but since the objects could literally be anything and have any set of inheritance, there is no way to know what the true base class for it is.
So my question is: will explicitly calling the child classes destructor automatically call all of the base destructors as well, like with delete, or is there no way to easily do this?