How to free a void pointer.
struct vStruct {
void *vPtr;
struct vStruct *next;
};
struct vStruct sObj;
struct vStruct *sObjNew = sObj;
delete sObjNew-&
How was vPtr
initialised?
malloc
, you should call free
.new
, you'd need to cast it to the correct (or a compatible) type before calling delete
to allow the correct destructor to be called.Note that your example code won't compile but suggests vPtr
is not being initialised at all. You must initialise vPtr
in all vStruct
instances you create. Attempting to free an uninitialised vPtr
would have undefined consequences but would likely crash.