Question about 'delete'

Ok, i was imagining how would i make dynamically allocated objects in my program allocate and delete correctly without the programmer having to use new and delete...

I was thinking of making the objects put a pointer to themselves on a void pointer type array and have them all being deleted using delete when the piece of code where theyll be used finishes.

But then i though, can delete delete any kind of data, or does it need to know the type?

I know it can delete any size of arrays, but can i give it a pointer to a class and it will destroy it correctly, without knowing the type of the deletable object? Or would i need separate arrays of pointers for each object type?



Now i decided to just make the objects have a method that allows you to delete them, and have them allocate all the data they use (wich should be the same as allocating the 'whole' object? right?) but id still like to know. :3
delete and delete[] operators must know the type of the object. What you are trying to do are called smart pointers.
They are not particularly hard to implement, to make them handle any data type you have to make them as templates.
Topic archived. No new replies allowed.