The following code compiles without any warning or error:
#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;
}
I am not understanding that as the scope of fun function is only in demo_class then how can it call fun2 function, should not it show error as the access of fun function only within the demo_class?