S
sam
For Example, If I delete two times like the below code, the program will
behave differently. is this correct?
As C++ FAQ the delete checks where or not f1 has memory. How can the
following program can go wrong?
class foo{
//
};
int main{
foo *f1 = new foo()
delete f1;
delete f1;
return (0);
}
C++ FAQ
[16.7] Do I need to check for NULL before delete p?
No!
The C++ language guarantees that delete p will do nothing if p is equal to
NULL. Since you might get the test backwards, and since most testing
methodologies force you to explicitly test every branch point, you should
not put in the redundant if test.
Wrong:
if (p != NULL)
delete p;
Right:
delete p;
Thanks
Sam
behave differently. is this correct?
As C++ FAQ the delete checks where or not f1 has memory. How can the
following program can go wrong?
class foo{
//
};
int main{
foo *f1 = new foo()
delete f1;
delete f1;
return (0);
}
C++ FAQ
[16.7] Do I need to check for NULL before delete p?
No!
The C++ language guarantees that delete p will do nothing if p is equal to
NULL. Since you might get the test backwards, and since most testing
methodologies force you to explicitly test every branch point, you should
not put in the redundant if test.
Wrong:
if (p != NULL)
delete p;
Right:
delete p;
Thanks
Sam