鉴于这一小段代码:
#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
时,第二个 assert( assert(NULL != p2);
) 没有失败,为什么?
输出 :everything is cool!
那么为什么断言p2
没有失败呢?