Suppose that I create a variable using the new operator, and then assign the resulting pointer to a void* variable. Much later in the program (perhaps when the user exits), I obtain the void* and free the memory with the delete operator.
If I delete the void*, how does the delete operator know how much memory to free (since void* can point to any type)? Is that information stored away so the computer knows what to do?
Here is an example:
myType* foo = new myType();
m_voidp = foo; // m_voidp is a member variable of type void*
... Much later in the code (not even in the same function)
delete m_voidp;
If I delete the void*, how does the delete operator know how much memory to free (since void* can point to any type)? Is that information stored away so the computer knows what to do?
Here is an example:
myType* foo = new myType();
m_voidp = foo; // m_voidp is a member variable of type void*
... Much later in the code (not even in the same function)
delete m_voidp;