+ 3
What is friend function???
Is this function have any significance in inheritance..??
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.
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.