I'm having trouble figuring out how to free memory allocated to a
struct. Here's my code:
I've also tried:Code://global defines struct Test { long l; int i; char c[20]; bool b; }; Test tTest; //initialization tTest.l=1233455; tTest.i=12; strcpy(tTest.c,"TestChar"); tTest.b=true; //test/deallocation (this is what I can't get right) if(&tTest) { MessageBox(NULL,"Allocated","Debug",NULL); tTest.l=NULL; tTest.i=NULL; strcpy(tTest.c,""); tTest.b=NULL; } else { MessageBox(NULL,"Memory cleared","Debug",NULL); }
With the second bit of code I get the following error:Code:Test* tTest; //initialization tTest=new Test[1]; tTest->l=1233455; tTest->i=12; strcpy(tTest->c,"TestChar"); tTest->b=true; //test/deallocation (this is what I can't get right) if(tTest) { MessageBox(NULL,"Allocated","Debug",NULL); delete [] tTest; } else { MessageBox(NULL,"Memory cleared","Debug",NULL); }
Debug Assertion Failed!
Anybody know what I'm doing wrong?



LinkBack URL
About LinkBacks


