Friend Function in C++

The central idea of encapsulation and data hiding concept is that any non-member function has no access permission to the private data of the class. The private members of the class are accessed only from member functions of that class. C++ allows a mechanism, in which a non-member function has access permission to the private members of the class. This can be done by declaring a non-member function friend to the class whose private data is to be accessed. The friend is a keyword. Consider the following example.

Read this article to understand Friend Function in C++ in depth

Have a doubt or thought? Join the discussion now

This is a companion discussion topic for the original entry at