Can a friend function be called by the object? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

29th Jun 2017, 8:33 PM
Shaikh Tahmidur
1 Answer
+ 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 () }
3rd Jul 2017, 3:06 PM
Mrinmay Bhattacharyya
Mrinmay Bhattacharyya - avatar