Hi all,
This is a great site. I'm doing the tutorials now, and I ran into a minor hitch:
Deleting the pointer before resetting it to 0 gives me this error:Quote:
The delete operator frees up the memory allocated through new. To do so, the syntax is as in the example.
After deleting a pointer, it is a good idea to reset it to point to 0.Code:delete ptr;
Debug Assertion Failed!
Expression: _BLOCK_TYPE_IS_VALID(pHead -> nBlockUse)
Resetting the pointer to 0 before I delete it seems to work, but I'm wondering - is there more to this than meets the eye?
code:
Code:int main()
{
int pointee = 1010;
int *pointer = new int;
cout<<"\nPointee is " << pointee << "";
pointer = &pointee;
cout<<"\nPointer is " << pointer << "";
pointer = 0;
cout<<"\nPointer is " << pointer << "";
delete pointer; //if I try deleting pointer before setting it to 0, I get the error
}