为什么类空指针/野指针可以调用类的成员函数?
#include <stdio.h>
int g_index = 10;
class A
{
public:
void Print1() { printf("g_index = %d\n", g_index); }
void Print2() { printf("m_index = %d\n", m_index); }
private:
int m_index;
};
int main()
{
A* a = NULL;
a->Print1(); // 可正常运行
//a->Print2();
return 0;
}
解释如下:http://blog.csdn.net/g5dsk/article/details/7017387
时间: 2024-12-06 08:42:51