[C++]空的对象指针可以调用成员函数

include

using namespace std;
class A{
public:
void func()
{
cout << "hahaha" << endl;
}
int m_num = 1;
};

int main()
{
A* ptr = NULL;
A obj;
obj.func();
cout<<obj.m_num<<endl;
ptr->func();
cout<m_num;
return 0;
}

输出结果
```cpp
hahaha
1
hahaha

不能调用类成员变量

posted @ 2018-12-20 15:14  zengzhaocheng  阅读(281)  评论(0编辑  收藏  举报