Hi,
Question relating to pointers, void* and destructors.
assuming I have code like this;
int main(int argc, char** argv)
{
X* x = new X();
void* tmp = x;
x = 0;
delete tmp;
return 0;
}
Can anybody tell me definitively that the above code leaks memory. I
mean I'm calling delete on the tmp pointer (type void*) however the
destructor isn't being called. I *definitely* have a leak on my hands
here, don't i. The reason I'm asking is cos the tool I'm evaluating for
leak analysis is not reporting anything for the above code. I see that
the X destructor is NOT called however it's still not reporting leaks
to me.
Am I correct in thinking this is a leak, aren't I. In order for it not
to leak, I would need to declare tmp thus;
X* tmp = x;
delete tmp;
That way the correct destructor will be called. Using a void* as in the
first scenario is a leak, correct?
thanks
g