delete and void *
Posted on 1998-05-05
I have a situation where rather than use a struct for access to elements within a database, I want to use an array of void pointers. This will allow me to create generic routines for many of the basic data access routines. When allocating space for the data, I will access a struct specific to the data file to let me know the size of the field and the type (Eg: char, double) allowing me to do something akin to:
void *genericPointer1 = (void *)new char;
void *genericPointer2 = (void *)new double;
So far, so good. The question I have is: Is there a defined result if deleting a void *? I think the result of
is undefined and should possibly be
delete (char *)genericPointer1;
Is the latter actually a legal statement?
I think the answer to this will probably be fairly simple, but if it isn't and more points need to be allocated to the question , just let me know.
Thanks in advance