0

Why the friend keyword is required in class in c++ ? Since, its function is same as that of member function.

Why the friend keyword is required in class c++ ? Since, its function is same as that of member function.

24th May 2018, 1:19 PM
Prasun Kumar Parate
Prasun Kumar Parate - avatar
1 Answer
0
First of all the friend keyword in C++ is not the same as a member function, and it serves a very specific purpose. Like : 1. Friend is used to grant access to private/protected members to non-member functions. 2. It's required because C++ enforces encapsulation, only members can access private data unless friendship is explicitly declared. 3. Member functions belong to the class, friend functions do not.
18th Jul 2025, 1:57 PM
Prabhat
Prabhat - avatar