Of course. How much of memory should be deleted? With untyped (void) pointer, a compiler could not find it out.
One of the valid approaches with C++ is this. Node object
obj
can be of some abstract base type, with virtual destructor. All the runtime types of the actual
obj
objects will be derived from this base type, overriding the destructor, which would be a mechanism to implement the release for this object, no matter how complex it is.
One of the simplest mechanisms would be to have an array of some, say, fixed type. Arrays can be deleted based on the current length known to the memory allocator via the operator
delete[]
:
http://www.cplusplus.com/reference/new/operator%20delete%5B%5D/[
^].
—SA