Madhav wrote:
Hi all,
I am a newbie in c++. I want to know what is the
philosophical reason behind the existence of friend functions. I
thought giving access to private data to a function which is not a
member of the class is a violation of encapsulation.
Thanks,
Madhav.
It is only giving access to *arbitrary* functions (e.g., by making data
public) that is a violation of encapsulation. Having the class identify
a *specific* function for access is not a violation of encapsulation,
since the class is giving that access. The function becomes part of the
encapsulation along with the member functions. That said, it should be
rare that non-members need such access.
Gregg