この小さなコードを考えると:
#include <iostream>
#include <assert.h>
using namespace std;
struct Foo
{
// something
};
int main()
{
Foo *p1 = new Foo;
Foo * p2 = p1;
assert(NULL != p1);
delete p1;
p1 = NULL;
assert(NULL != p2);
delete p2;
cout << "everything is cool!" << endl;
return 0;
}
を削除するp1
と、2番目のassert(assert(NULL != p2);
)が失敗しません。なぜですか?
出力 :everything is cool!
では、なぜのアサートがp2
失敗しないのですか?