#include<bits/stdc++.h>
using namespace std;
class Person{
public:
void showClassName(){
cout<<"this is person class "<<endl;
}
void showPersonAge(){
if(this==NULL){
return;
}
cout<<"age= "<<m_Age<<endl;
}
int m_Age;
};
void test01(){
Person *p=NULL;
p->showClassName();
p->showPersonAge();
}
int main()
{
//c++中空指针也是可以调用成员函数的,但是也要注意有没有用到this指针
//如果用到this指针,需要加以判断代码的健壮性
test01();
return 0;
}
4-空指针访问成员函数
最新推荐文章于 2024-05-10 21:41:33 发布