以下代码编译时没有任何警告或错误:
#include <iostream>
using namespace std;
class demo_class
{
int x;
float y;
public:
void fun(void);
};
void fun2(void)
{
cout<<"i am fun2\n";
}
void demo_class::fun(void)
{
cout<<"i am fun\n";
cout<<"i can call fun2\n";
fun2();
}
int main()
{
demo_class ob1;
ob1.fun();
return 0;
}
我不明白由于 fun 函数的范围仅在 demo_class 中,那么它如何调用 fun2 函数,它不应该显示错误作为仅在 demo_class 内访问 fun 函数吗?