/* C++中的空指针也可以调用成员函数,但是也要注意有没有用到this指针
如果用到this指针,需要加以判断保证代码的健壮性 */
#include "pch.h"
#include <iostream>
using namespace std
;
class person {
public:
void showclassname() {
cout
<< "person的名称" << endl
;
}
void showpersonage() {
if (this == NULL) {
return;
}
cout
<< "年龄" <<this-> m_age
<< endl
;
}
int m_age
;
};
void test01() {
person
* p
=NULL;
p
->showclassname();
p
->showpersonage();
}
int main()
{
}