+ 3

What is friend function???

Is this function have any significance in inheritance..??

31st Oct 2016, 10:45 AM
Shruti Singh
Shruti Singh - avatar
2 odpowiedzi
0
The effect can be simulated more or less by making protected proxy functions in friended base classes, so there is no strict need for granting friendship to a class or virtual method heirarchy. The significance in inheritance is complex that is why it should avoid in friend function.
31st Oct 2016, 1:05 PM
Shovan Lal Saha
Shovan Lal Saha - avatar
0
A friend function can access private variables and methods in the class. Operators are often not declared within the class' scope but rather as public functions with friendship. That way you can separate the definitions of the class and the operator. Friends break the concept of encapsulation and are intended as such: Sometimes you need an outsider to have access to the private stuff. Consider functions for memory management, logging or debugging. Those typically do not belong to any class but still need to access the private parts of a class.
31st Oct 2016, 3:16 PM
Ullrich Franke
Ullrich Franke - avatar