#include<iostream>
using namespace std;
#include<assert.h>
class Person
{
public:
void showClassNmae()
{
cout << "this is class Person" << endl;
}
void showPersonAge()
{
//为了防止对空指针的访问
/*assert(this);*/
if (this == NULL)
{
return;
}
cout <<this-> m_Age << endl;//这里的m_Age实质上是类成员的m_Age,也就是this->m_Age;
}
int m_Age;
};
void test01()
{
Person* p = NULL;
p->showClassNmae();
p->showPersonAge();//这里对NULL进行了访问,导致程序出错 p对象中的this指向空,空的m_Age肯定是出错了
}
int main()
{
test01();
}