0
Can a friend function be called by the object?
I mean object should call the friend function which belongs to the object's class
1 Resposta
+ 1
Actually Friend functions are not a part of the class!
Its a friend of the class, that means that it can access the data members or member functions of the class without being an actual member of the class. Hence it cannot be called by the objects.
The difference is that u can directly use the function.
For eg:
class stud
{int a;
int b;
public:
void func ();
friend void func2 ();
};
void main ()
{stud obj;
int k;
obj.func (k);
//suppose its changes value of variable a
//we can directly use the friend function than using
//obj.func (k)
func2 (k);
//suppose it has the same coding as func ()
}