我想知道为什么以下小程序不会导致NullPointerException.有任何想法吗?输出是2x Hello World !!! 在我的macbook上使用clang-500.2.79.
#include <iostream>
using namespace std;
class Strange {
public:
Strange() {}
virtual ~Strange() {}
void sayHello() {
cout<<endl<<"Hello World!!!"<<endl;
}
};
int main(void) {
Strange* s = new Strange();
delete s; s = NULL;
s->sayHello();
(*s).sayHello();
return 0;
}
Run Code Online (Sandbox Code Playgroud)