I have a simple class:
If I declare an instance of gog in main(), I always receive an assertion error whenever the program ends. So I checked out dbgheap.c and read:Code:class gog { private: char *s; int slen; public: gog (const char*s) { slen = strlen(s); s = new char [slen]; } gog (int l = 4) : slen(l) { s = new char [l]; } ~gog () { if (s) { if (slen < 2) delete s; else delete[] s; } } };
/*
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
about the specific assert.
The code I'm using looks right. Is there something I'm forgetting? All I'm doing is creating an instance. If I use the default constructor or I pass in a string or anything it fails... If I comment out the deletes then it works fine. Argh! What's wrong?
thanks for any help!