#include<iostream>
using namespace std;
#include<string>
class Person
{
public:
void showClassName()
{
cout << "this is in Person class" << endl;
}
void showPersonAge()
{
if(!this)
{
return;
}//判断指针是否为空,防止数据被修改
cout << "age = " << this -> m_Age << endl;
}
int m_Age;
};
void test01()
{
Person *p = NULL;
p->showClassName();
p->showPersonAge();
}
int main()
{
test01();
return 0;
}
空指针学习
最新推荐文章于 2022-01-17 14:52:41 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)