读别人的代码,发现了这个现象。竟然能这样!正常执行无误。野指针不野。 环境是VS2012下(据说VC6也可以)
#include "stdafx.h"
#include <process.h>
class test
{
public:
int b;
void fun() ;
};
void test::fun()
{
int a = 99;
//b = 1; //运行时出错。
printf("This is a Test! \n\r");
}
class test* p = 0;
int _tmain(int argc, _TCHAR* argv[])
{
p->fun();
((class test*)(NULL))->fun();
((class test*)(67))->fun();
system("pause");
return 0;
}