6.1 如果成员函数没有用到this,那么空指针可以直接访问
6.2 如果成员函数用的this指针,就要注意,可以加if判断,如果this为NULL就return
#include#include using namespace std; class Nick { public: void show() { cout << "void::Nick show()" << endl; } void showAge() { if (this == NULL) { return; } cout << this->m_age << endl;// NULL -> m_Age } int m_age; }; void test01() { Nick *nick = NULL; nick->show(); nick->showAge(); } int main(){ test01(); system("pause"); return 0; }



