C++ Question
Could you show me some code if I wanted Arrays of Menu''s and Buttons, cause I cant seem to get it to work.
this site explains such a situation pretty well, it suggest c++ does in fact have garbage collection
http://library.advanced.org/tq-admin/day.cgi
http://library.advanced.org/tq-admin/day.cgi
quote:
I just got an Assertion Error. What is that?
assert(a != b); // assume a != b, if it isn''t - there''s wrong! complain!
When the expression sent to assert() is false there''s a problem - if a equals b, you''ll get an assertion error. For example assert(0 != NULL) would generate an assertion error.
A common use for this is assert(ptr != 0). (ASSERT is the MFC variant - as opposed to the ANSI C++ assert)
"Paranoia is the belief in a hidden order behind the visible." - Anonymous
For instance MFC does, and so does the C++ Run-Time debug libraries (I suppose - it seems it''s there they''re coming from in your case) - and heck, even I use them Of course I wrote my own assert function hehe.
"Paranoia is the belief in a hidden order behind the visible." - Anonymous
"Paranoia is the belief in a hidden order behind the visible." - Anonymous
Once you free the memory that has been taken up by the class, then that memory is free and when you allocate memory for another class or something, then it might choose to use the memory you freed some time ago... so right after you free the memory, the pointer might be still valid (in general it shouldn''t be) and you could still use it, but it might be overwritten by other memory allocations that you might use for other classes or variables...
Assertion is very very very helpful.
Suppose you are doing a simple vector class (a pretty nice assertion example), with a size... You should do it this way:
Tadaa! Check out the ASSERT in the operator. It is used so when iPos is out of range, then it stops the program.
ASSERT is only used in DEBUG mode... You put it where you want (some useful places, but there are many), and when you switch to release mode, every ASSERT is removed automatically, so the program is faster and doesn't make those checks.
Very useful function, the MFC one is a little fuzzy... personnally I don't care, but if you want to make your own assertion function go on. It's easy.
Edited by - Poltras on July 9, 2000 10:43:26 PM
Suppose you are doing a simple vector class (a pretty nice assertion example), with a size... You should do it this way:
template<Element_t>class myVECTOR { int iSize; Element_t *Tata; myVECTOR() { iSize=15; // 15 elements maximum by default. Tata=new Element_t[iSize]; } ~myVECTOR() { delete Tata; } HRESULT Resize(int newSize) { ASSERT(newSize>0); Element_t *Toto = new Element_t[newSize]; if(Toto) { memcpy(Toto, Tata, sizeof(Element_t)*(newSize>iSize?iSize:newSize)); delete Tata; Tata = Toto; return S_OK; } return E_FAIL; } Element_t& operator[](int iPos) { ASSERT(iPos>=0 && iPos<iSize); return Tata[iPos]; }}
Tadaa! Check out the ASSERT in the operator. It is used so when iPos is out of range, then it stops the program.
ASSERT is only used in DEBUG mode... You put it where you want (some useful places, but there are many), and when you switch to release mode, every ASSERT is removed automatically, so the program is faster and doesn't make those checks.
Very useful function, the MFC one is a little fuzzy... personnally I don't care, but if you want to make your own assertion function go on. It's easy.
Edited by - Poltras on July 9, 2000 10:43:26 PM
Now I know what I'm made of, and I'm afraid of it...
I now understand assertion and are probally going to use it in a couple places, but I still need help on the freeing of the memory. Could someone please show me code on how to free memory when You have Instances of a class in Instances of a class in Instances of a class.(ya gett it?). Like:
if thing is an array of class2''s, and otherthing is an array of class3''s. How would I clear all the memory if I had lets say:
class1 *mainclass;
mainclass = new class1[5];
Now how in the hell would I free all this memory, cause I get Assertion errors every way I try. Thanks for the VERY needed help
class class1{class2 *thing;};class class2{class3 *otherthing;};class class3{char *stringcrap;};
if thing is an array of class2''s, and otherthing is an array of class3''s. How would I clear all the memory if I had lets say:
class1 *mainclass;
mainclass = new class1[5];
Now how in the hell would I free all this memory, cause I get Assertion errors every way I try. Thanks for the VERY needed help
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement