When and when not to use friend function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

When and when not to use friend function

I am a bit confused if to make all function either member function or friend function since either of these has access to private variables.

20th Dec 2016, 2:28 PM
Richard Dan
Richard Dan - avatar
2 Answers
+ 6
Make them friend (always the best choice)
20th Dec 2016, 2:29 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 4
use friend functions only when you think the functions may need to change private value....if you want your functions not to change value of other classes or if you want private value to be untouched by a function, don't make them friend
20th Dec 2016, 2:32 PM
Towfique Kabir
Towfique Kabir - avatar