Hi ,
I am just curious to know that , why i am not able to compile below code if i define access function inside the class.
i am able to execute another friend function inside the class. Does it mean class scope is responsible for the execution of other friend function or due to having global scope it execute code oustside class.
#include<iostream>
#include<memory>
#include<process.h>
using namespace std;
class a
{
int i;
public:
void display ()
{
cout<<"Hello";
}
/*friend void access();*/
friend void access()
{ a x;
x.i=10;
cout<<x.i;
}
/* friend void access(a & x) works fine if object passed explicitly
{
x.i=10;
cout<<x.i;
}*/
friend a operator --(a &x)
{
x.i=x.i-1;
return x;
}
};
/*void access() it works fine
{
a obj;
obj.i=10;
cout<<obj.i;
}*/
int main()
{
a obj;
--obj;
access();//Error:Access was not declared in this scope
//access(obj)
return 1;
}