0

What is friend function?

Clarify all the workings of 'friend function'

4th Jan 2018, 1:34 AM
Hariprasanth Krishnamoorthy
4 Answers
+ 1
When a function is declared as a friend, it has access to all members of a class (including private members).
4th Jan 2018, 3:00 AM
Diego
Diego - avatar
+ 1
Think of it like this, a friend function has access to the member variables of another class but does not belong to that class itself. The only restrictions would be private variables (if I remember correctly) A commenter once explained it as how your friend can use your cup, and your toilet (hopefully not at the same time) in your house but it would be strange if he/she was suddenly searching your bedroom. I stand to be corrected by the wag
4th Jan 2018, 1:42 AM
Kopano Phutiyagae
Kopano Phutiyagae - avatar
0
@Diego Thanks for the clarity mate
4th Jan 2018, 10:13 AM
Kopano Phutiyagae
Kopano Phutiyagae - avatar
0
Your welcome! I tryed to write an example but i had some problems with internet conection. Sorry for the late answer.Here's an example https://code.sololearn.com/cjE6b8OV4THU/?ref=app
4th Jan 2018, 4:44 PM
Diego
Diego - avatar