编译器原理(一):类成员函数

为什么类空指针/野指针可以调用类的成员函数?

#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

posted on 2016-07-07 17:05  木子№墨轲  阅读(152)  评论(0编辑  收藏  举报

导航