Is it possible?
class sample {
private:
int x;
public:
friend void fun();
};
friend
function with no argument!
In my opinion not possible
Because friend functions are not "member" of classes So we can not call with class object
like:
sample s;
s.fun();
Yes, you can:
void fun()
{
sample s;
s.x++; // OK, fun() is a friend of sample
}
or
sample globalSample; // yikes, a global variable
void fun()
{
int i = globalSample.x; // OK, fun() is a friend of sample
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With